Only limit menu position if menu width smaller than screen width

This commit is contained in:
Jaex 2016-10-01 19:08:08 +03:00
parent df9a99b264
commit 5600d69936

View file

@ -57,36 +57,6 @@ private void CreateMenu()
Text = "RegionCaptureFormMenu"
};
menuForm.LocationChanged += (sender, e) =>
{
Rectangle rectMenu = menuForm.Bounds;
Rectangle rectScreen = CaptureHelpers.GetScreenBounds();
Point pos = rectMenu.Location;
if (rectMenu.X < rectScreen.X)
{
pos.X = rectScreen.X;
}
else if (rectMenu.Right > rectScreen.Right)
{
pos.X = rectScreen.Right - rectMenu.Width;
}
if (rectMenu.Y < rectScreen.Y)
{
pos.Y = rectScreen.Y;
}
else if (rectMenu.Bottom > rectScreen.Bottom)
{
pos.Y = rectScreen.Bottom - rectMenu.Height;
}
if (pos != rectMenu.Location)
{
menuForm.Location = pos;
}
};
menuForm.SuspendLayout();
tsMain = new ToolStripEx()
@ -623,9 +593,39 @@ private void CreateMenu()
Rectangle rectActiveScreen = CaptureHelpers.GetActiveScreenBounds0Based();
if (rectActiveScreen.Width > tsMain.Width)
if (tsMain.Width < rectActiveScreen.Width)
{
menuForm.Location = new Point(rectActiveScreen.X + rectActiveScreen.Width / 2 - tsMain.Width / 2, rectActiveScreen.Y + 20);
menuForm.LocationChanged += (sender, e) =>
{
Rectangle rectMenu = menuForm.Bounds;
Rectangle rectScreen = CaptureHelpers.GetScreenBounds();
Point pos = rectMenu.Location;
if (rectMenu.X < rectScreen.X)
{
pos.X = rectScreen.X;
}
else if (rectMenu.Right > rectScreen.Right)
{
pos.X = rectScreen.Right - rectMenu.Width;
}
if (rectMenu.Y < rectScreen.Y)
{
pos.Y = rectScreen.Y;
}
else if (rectMenu.Bottom > rectScreen.Bottom)
{
pos.Y = rectScreen.Bottom - rectMenu.Height;
}
if (pos != rectMenu.Location)
{
menuForm.Location = pos;
}
};
}
else
{