Skip to Content

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 16, 2016 at 11:03 AM

    Hi Szabolcs,

    First of all, I would like to suggest you to use the ItemEvent, in specific event et_FORM_DRAW.

    About your code. I believe that you have a mistake in your code.

    newBtn.Top = megsemBtn.Left;

    I believe that you want is this:

    newBtn.Top = megsemBtn.Top;

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded

    • This mistake wasn't in my code originally, it just slipped in when I copied it to the post. So the Top property is set properly. But the et_FORM_DRAW event did the trick, not it draws the button properly when the user resizes the windows. Thanks!