HamBook – Diff between revs 29 and 54
?pathlinks?
Rev 29 | Rev 54 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | // Derived from https://stackoverflow.com/questions/63917294/custom-paint-in-toolstriptextbox |
1 | // Derived from https://stackoverflow.com/questions/63917294/custom-paint-in-toolstriptextbox |
|
2 | using System; |
2 | |
|
3 | using System.Collections.Generic; |
- | ||
4 | using System.ComponentModel; |
3 | using System.ComponentModel; |
|
5 | using System.Drawing; |
4 | using System.Drawing; |
|
6 | using System.Linq; |
- | ||
7 | using System.Text; |
- | ||
8 | using System.Threading.Tasks; |
- | ||
9 | using System.Windows.Forms; |
5 | using System.Windows.Forms; |
|
10 | using System.Windows.Forms.Design; |
6 | using System.Windows.Forms.Design; |
|
Line 11... | Line 7... | |||
11 | |
7 | |
|
12 | namespace HamBook.Utilities.Controls |
8 | namespace HamBook.Utilities.Controls |
|
13 | { |
9 | { |
|
14 | [DesignerCategory("ToolStrip"), |
10 | [DesignerCategory("ToolStrip")] |
|
15 | ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All)] |
11 | [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All)] |
|
16 | public class ScrollableToolStripComboBox : ToolStripComboBox |
12 | public class ScrollableToolStripComboBox : ToolStripComboBox |
|
17 | { |
- | ||
18 | [Browsable(true), |
13 | { |
|
19 | EditorBrowsable(EditorBrowsableState.Always), |
- | ||
20 | DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), |
14 | public ScrollableToolStripComboBox() |
|
21 | Description("Mouse scrolling")] |
15 | { |
|
- | 16 | ComboBox.MouseWheel += ComboBox_MouseWheel; |
||
Line 22... | Line 17... | |||
22 | public event MouseEventHandler MouseWheel; |
17 | } |
|
23 | |
18 | |
|
24 | /// <summary> |
19 | /// <summary> |
|
25 | /// The image that will be displayed on the item. |
20 | /// The image that will be displayed on the item. |
|
26 | /// </summary> |
21 | /// </summary> |
|
27 | [Browsable(true), |
22 | [Browsable(true)] |
|
28 | EditorBrowsable(EditorBrowsableState.Always), |
23 | [EditorBrowsable(EditorBrowsableState.Always)] |
|
29 | DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), |
24 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
|
30 | Category("Appearance"), |
25 | [Category("Appearance")] |
|
31 | Description("The image associated with the object.")] |
26 | [Description("The image associated with the object.")] |
|
- | 27 | public override Image Image |
||
32 | public override Image Image { get => base.Image; set => base.Image = value; } |
28 | { |
|
- | 29 | get => base.Image; |
||
Line 33... | Line 30... | |||
33 | |
30 | set => base.Image = value; |
|
34 | public new ComboBoxStyle DropDownStyle { get => base.DropDownStyle; set => base.DropDownStyle = value; } |
31 | } |
|
- | 32 | |
||
35 | |
33 | public new ComboBoxStyle DropDownStyle |
|
36 | public ScrollableToolStripComboBox() : base() |
34 | { |
|
Line -... | Line 35... | |||
- | 35 | get => base.DropDownStyle; |
||
- | 36 | set => base.DropDownStyle = value; |
||
- | 37 | } |
||
- | 38 | |
||
- | 39 | [Browsable(true)] |
||
- | 40 | [EditorBrowsable(EditorBrowsableState.Always)] |
||
37 | { |
41 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
|
38 | ComboBox.MouseWheel += ComboBox_MouseWheel; |
42 | [Description("Mouse scrolling")] |
|
39 | } |
43 | public event MouseEventHandler MouseWheel; |
|
40 | |
44 | |
|
Line 47... | Line 51... | |||
47 | { |
51 | { |
|
48 | base.OnParentChanged(oldParent, newParent); |
52 | base.OnParentChanged(oldParent, newParent); |
|
Line 49... | Line 53... | |||
49 | |
53 | |
|
50 | if (newParent != null && newParent is ToolStripDropDownMenu) |
54 | if (newParent != null && newParent is ToolStripDropDownMenu) |
|
51 | { |
55 | { |
|
52 | newParent.Paint -= new PaintEventHandler(OnParentPaint); |
56 | newParent.Paint -= OnParentPaint; |
|
53 | newParent.Paint += new PaintEventHandler(OnParentPaint); |
57 | newParent.Paint += OnParentPaint; |
|
Line 54... | Line 58... | |||
54 | } |
58 | } |
|
55 | |
59 | |
|
56 | if (oldParent != null) |
60 | if (oldParent != null) |
|
Line 57... | Line 61... | |||
57 | oldParent.Paint -= new PaintEventHandler(OnParentPaint); |
61 | oldParent.Paint -= OnParentPaint; |
|
58 | } |
62 | } |
|
59 | |
63 | |
|
60 | private void OnParentPaint(object sender, PaintEventArgs e) |
64 | private void OnParentPaint(object sender, PaintEventArgs e) |
|
61 | { |
65 | { |
|
62 | if (Image is null || |
66 | if (Image is null || |
|
Line 63... | Line 67... | |||
63 | (sender is ContextMenuStrip cmnu && |
67 | (sender is ContextMenuStrip cmnu && |
|
64 | !cmnu.ShowImageMargin && !cmnu.ShowCheckMargin)) |
68 | !cmnu.ShowImageMargin && !cmnu.ShowCheckMargin)) |
|
65 | return; |
69 | return; |
|
Line 72... | Line 76... | |||
72 | r.X = Bounds.Right + r.Width - ContentRectangle.X; |
76 | r.X = Bounds.Right + r.Width - ContentRectangle.X; |
|
Line 73... | Line 77... | |||
73 | |
77 | |
|
74 | e.Graphics.DrawImage(Image, r); |
78 | e.Graphics.DrawImage(Image, r); |
|
75 | } |
79 | } |
|
76 | } |
80 | } |
|
77 | } |
81 | } |