MenuButton changes

This commit is contained in:
Jaex 2015-11-25 01:27:02 +02:00
parent 1486c80318
commit 35116b47c8
4 changed files with 21 additions and 11 deletions

View file

@ -104,7 +104,6 @@ private void InitializeComponent()
//
resources.ApplyResources(this.btnImport, "btnImport");
this.btnImport.Menu = this.cmsImport;
this.btnImport.MenuX0 = true;
this.btnImport.Name = "btnImport";
this.btnImport.UseVisualStyleBackColor = true;
//
@ -112,7 +111,6 @@ private void InitializeComponent()
//
resources.ApplyResources(this.btnExport, "btnExport");
this.btnExport.Menu = this.cmsExport;
this.btnExport.MenuX0 = true;
this.btnExport.Name = "btnExport";
this.btnExport.UseVisualStyleBackColor = true;
//

View file

@ -35,7 +35,7 @@ public class MenuButton : Button
public ContextMenuStrip Menu { get; set; }
[DefaultValue(false)]
public bool MenuX0 { get; set; }
public bool ShowMenuUnderCursor { get; set; }
protected override void OnMouseDown(MouseEventArgs mevent)
{
@ -43,7 +43,18 @@ protected override void OnMouseDown(MouseEventArgs mevent)
if (Menu != null && mevent.Button == MouseButtons.Left)
{
Menu.Show(this, MenuX0 ? 0 : mevent.X, Height);
Point menuLocation;
if (ShowMenuUnderCursor)
{
menuLocation = mevent.Location;
}
else
{
menuLocation = new Point(0, Height);
}
Menu.Show(this, menuLocation);
}
}
@ -51,12 +62,15 @@ protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
int arrowX = ClientRectangle.Width - 14;
int arrowY = ClientRectangle.Height / 2 - 1;
if (Menu != null)
{
int arrowX = ClientRectangle.Width - 14;
int arrowY = ClientRectangle.Height / 2 - 1;
Brush brush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
Point[] arrows = new Point[] { new Point(arrowX, arrowY), new Point(arrowX + 7, arrowY), new Point(arrowX + 3, arrowY + 4) };
pevent.Graphics.FillPolygon(brush, arrows);
Brush brush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
Point[] arrows = new Point[] { new Point(arrowX, arrowY), new Point(arrowX + 7, arrowY), new Point(arrowX + 3, arrowY + 4) };
pevent.Graphics.FillPolygon(brush, arrows);
}
}
}
}

View file

@ -170,7 +170,6 @@ private void InitializeComponent()
//
resources.ApplyResources(this.mbLoadImage, "mbLoadImage");
this.mbLoadImage.Menu = this.cmsLoadImage;
this.mbLoadImage.MenuX0 = true;
this.mbLoadImage.Name = "mbLoadImage";
this.mbLoadImage.UseVisualStyleBackColor = true;
//

View file

@ -185,7 +185,6 @@ private void InitializeComponent()
//
resources.ApplyResources(this.btnLanguages, "btnLanguages");
this.btnLanguages.Menu = this.cmsLanguages;
this.btnLanguages.MenuX0 = true;
this.btnLanguages.Name = "btnLanguages";
this.btnLanguages.UseVisualStyleBackColor = true;
//