|
| 1 | +using System; |
| 2 | +using System.Drawing; |
| 3 | +using System.Windows.Forms; |
| 4 | + |
| 5 | +namespace XRay.SdkControls |
| 6 | +{ |
| 7 | + public class MenuButton : Button |
| 8 | + { |
| 9 | + private ContextMenu menu = new ContextMenu(); |
| 10 | + |
| 11 | + protected override void OnClick(EventArgs e) |
| 12 | + { |
| 13 | + // for ContextMenuStrip |
| 14 | + //var screenPoint = PointToScreen(new Point(Left, Bottom)); |
| 15 | + //var currentScreen = Screen.FromPoint(screenPoint); |
| 16 | + //var flip = screenPoint.Y + menu.Size.Height > currentScreen.WorkingArea.Height; |
| 17 | + //menu.Show(this, new Point(0, flip ? -menu.Height : Height)); |
| 18 | + menu.Show(this, new Point(0, Height)); |
| 19 | + base.OnClick(e); |
| 20 | + } |
| 21 | + |
| 22 | + protected override void OnPaint(PaintEventArgs e) |
| 23 | + { |
| 24 | + base.OnPaint(e); |
| 25 | + int arrowX = ClientRectangle.Width-14; |
| 26 | + int arrowY = ClientRectangle.Height/2-1; |
| 27 | + var brush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow; |
| 28 | + var arrowPoints = new [] |
| 29 | + { |
| 30 | + new Point(arrowX, arrowY), |
| 31 | + new Point(arrowX+7, arrowY), |
| 32 | + new Point(arrowX+3, arrowY+4) |
| 33 | + }; |
| 34 | + e.Graphics.FillPolygon(brush, arrowPoints); |
| 35 | + } |
| 36 | + |
| 37 | + public ContextMenu Menu |
| 38 | + { |
| 39 | + get { return menu; } |
| 40 | + } |
| 41 | + } |
| 42 | +} |
0 commit comments