Skip to Content
Nov 16, 2016 at 09:04 AM

Button moves on resize


I am using SAP Business One 9.2 SDK UI API (C#) to manipulate a system form (Items form specifically). I would like to place a new button and attach functionality (event listener to it). I am subscribed to the Menu Event listener with:

Application.MenuEvent += new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler();

And If the clicked menu's ID (and beforevent == false) isthe Item form's menuid, I grab the active form and try to add a new button. Code:

var oForm = SBOApp.Forms.ActiveForm;
oForm.PaneLevel = 0;
Button megsemBtn = (Button)oForm.Items.Item("2").Specific;//the cancel button
Item newBtn = oForm.Items.Add("newBtn", BoFormItemTypes.it_BUTTON);
newBtn.Left = megsemBtn.Left + 200;
newBtn.Top = megsemBtn.Left;
Button newBtnBtn = (Button)newBtn.Specific;
newBtnBtn.Caption = "test";
newBtn.Width = 80;
newBtn.Height = megsemBtn.Height;

If I open the form, the button is displayed correctly (even though it appears ~0.5 sec after the form is displayed), but If I resize the From, it either goes downwards a bit, or completely leaves the form (it exists, I checked, I just can't see it). The other buttons scale perfectly with the window. Why this one isn't? I even check the XML export of the form (with the button added) and it looks the same.