Saturday, 10 August 2013

Context menu below button, however parts of it can be seen outside of the window

Context menu below button, however parts of it can be seen outside of the
window

I'm working on a button which opens a context menu below that button. This
code is working fine, however when my window isn't maximized the context
menu does in fact open below that button, however parts of the context
menu can also be seen right outside of the window and I don't like that:
if (e.Button == MouseButtons.Left)
{
c1.Show(b10, new Point(0, b10.Height));
}
That's why I'm currently using this code, however it seems to be quite
inefficient and won't display correctly at non standard DPI settings:
(Anything but 100%, 125%, 150% and 200%)
if (e.Button == MouseButtons.Left)
{
Graphics g = this.CreateGraphics();
if (g.DpiX < 120)
{
c1.Show(b10, new Point(-100, b10.Height));
}
else if (g.DpiX >= 120 && g.DpiX < 144)
{
c1.Show(b10, new Point(-110, b10.Height));
}
else if (g.DpiX == 144)
{
if (g.DpiX > 144)
{
c1.Show(b10, new Point(-160, b10.Height));
}
else
{
c1.Show(b10, new Point(-134, b10.Height));
}
}
else
{
c1.Show(b10, new Point(-160, b10.Height));
}
W.Select();
}
Suggestions?

No comments:

Post a Comment