Files
mRemoteNG/mRemoteV1/UI/Controls/ToolStripSplitButton.cs
Sean Kaim e92a76f95b "return ;" annoyed me...
And I did a find and replace in the solution instead of the one file I
was working on... So I'm going with it...
2017-01-11 16:56:14 -05:00

59 lines
1.4 KiB
C#

using System.Drawing;
using System.Windows.Forms;
namespace mRemoteNG.UI.Controls
{
public class ToolStripSplitButton : System.Windows.Forms.ToolStripSplitButton
{
public new ToolStripDropDown DropDown
{
get { return base.DropDown; }
set
{
if (base.DropDown != value)
{
base.DropDown = value;
base.DropDown.Closing += DropDown_Closing;
}
}
}
private void DropDown_Closing(object sender, ToolStripDropDownClosingEventArgs e)
{
if (e.CloseReason != ToolStripDropDownCloseReason.AppClicked)
{
return;
}
Rectangle dropDownButtonBoundsClient = DropDownButtonBounds; // Relative to the ToolStripSplitButton
dropDownButtonBoundsClient.Offset(Bounds.Location); // Relative to the parent of the ToolStripSplitButton
Rectangle dropDownButtonBoundsScreen = GetCurrentParent().RectangleToScreen(dropDownButtonBoundsClient); // Relative to the screen
if (dropDownButtonBoundsScreen.Contains(Control.MousePosition))
{
e.Cancel = true;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
_dropDownVisibleOnMouseDown = DropDown.Visible;
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (_dropDownVisibleOnMouseDown)
{
DropDown.Close();
}
else
{
base.OnMouseUp(e);
}
}
private bool _dropDownVisibleOnMouseDown;
}
}