winformstoolstriptoolstripbutton

ToolStripDropDownButton does not show items when right aligned


I developed a Winforms application that has a Toolbar. The last element in the toolbar is a ToolStripDropDownButton with some items.

I needed this button to be shown apart from all other toolbar buttons, so I set the Alignment property to right.

In my PC this works perfectly, however, when I moved the whole Visual Studio project to my notebook and then ran the application, the menu items are not shown when I click the button, however, the dropdown button changes color indicating that it was selected.

At design time, items are shown correctly.

What is happening here and is it possible to solve it? At the moment, I set the button alignment to left, so that it is shown together with other toolbar buttons.

Thanks Jaime


Solution

  • Check your DPI settings on your notebook. It is likely changing the size and padding of your elements. You can get around this by checking for the system's DPI value and calculating sizes of controls based on that.

    var graphics = this.CreateGraphics();
    var dpiX = graphics.DpiX / 96d; // Default DPI
    var dpiY = graphics.DpiY / 96d; // Default DPI
    myToolbar.Width = myWidth * dpiX;
    myToolbar.Height= myHeight * dpiY;