diff --git a/ShortcutUtil/ListBoxButton.cs b/ShortcutUtil/ListBoxButton.cs old mode 100644 new mode 100755 index 46518cd..e5f6b49 --- a/ShortcutUtil/ListBoxButton.cs +++ b/ShortcutUtil/ListBoxButton.cs @@ -9,6 +9,28 @@ namespace ShortcutUtil { + public class ListBoxEx : ListBox + { + private bool designMode; + public ListBoxEx() : base() + { + designMode = System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime; + } + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + if (!designMode) + { + cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED + cp.Style &= ~0x040; // Turn off CS_CLASSDC + } + return cp; + } + } + } + public interface IListBoxControl { void Hover(); @@ -34,26 +56,11 @@ public int? IndexOver { get; private set; } - private MethodInfo refreshItem; public ListBoxControl(T control, ListBox listBox) { Control = control; this.listBox = listBox; listBox.MouseMove += ListBoxMouseMove; - - refreshItem = listBox.GetType().GetMethod("RefreshItem", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(int) }, null); - } - - private void RefreshItem(int index) - { - listBox.BeginUpdate(); - object item = listBox.Items[index]; - listBox.Items.RemoveAt(index); - listBox.Items.Insert(index, item); - listBox.EndUpdate(); - //listBox.Items[index] = item; - //listBox.Items[index] = - //if (refreshItem != null) refreshItem.Invoke(listBox, new object[] { index }); } public Rectangle BoundsInList(int index) @@ -77,25 +84,22 @@ if (nowIndexOver != IndexOver) { - if (IndexOver.HasValue) RefreshItem(IndexOver.Value); IndexOver = nowIndexOver; - if (IndexOver.HasValue) RefreshItem(IndexOver.Value); + listBox.Invalidate(); } } - public void RenderToItem(DrawItemEventArgs e) + public void RenderToItem(int index, Graphics g) { using (Bitmap b = new Bitmap(Control.Size.Width, Control.Size.Height)) { - if (e.Index == IndexOver) + if (index == IndexOver) { Control.Hover(); } Control.DrawToBitmap(b, new Rectangle(new Point(), Control.Size)); - Point offsetLoc = e.Bounds.Location; - offsetLoc.Offset(Control.Location); - e.Graphics.DrawImage(b, offsetLoc.X, offsetLoc.Y); - if (e.Index == IndexOver) + g.DrawImage(b, Control.Location.X, Control.Location.Y); + if (index == IndexOver) { Control.Unhover(); } diff --git a/ShortcutUtil/ListBoxButton.cs b/ShortcutUtil/ListBoxButton.cs old mode 100644 new mode 100755 index 46518cd..e5f6b49 --- a/ShortcutUtil/ListBoxButton.cs +++ b/ShortcutUtil/ListBoxButton.cs @@ -9,6 +9,28 @@ namespace ShortcutUtil { + public class ListBoxEx : ListBox + { + private bool designMode; + public ListBoxEx() : base() + { + designMode = System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime; + } + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + if (!designMode) + { + cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED + cp.Style &= ~0x040; // Turn off CS_CLASSDC + } + return cp; + } + } + } + public interface IListBoxControl { void Hover(); @@ -34,26 +56,11 @@ public int? IndexOver { get; private set; } - private MethodInfo refreshItem; public ListBoxControl(T control, ListBox listBox) { Control = control; this.listBox = listBox; listBox.MouseMove += ListBoxMouseMove; - - refreshItem = listBox.GetType().GetMethod("RefreshItem", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(int) }, null); - } - - private void RefreshItem(int index) - { - listBox.BeginUpdate(); - object item = listBox.Items[index]; - listBox.Items.RemoveAt(index); - listBox.Items.Insert(index, item); - listBox.EndUpdate(); - //listBox.Items[index] = item; - //listBox.Items[index] = - //if (refreshItem != null) refreshItem.Invoke(listBox, new object[] { index }); } public Rectangle BoundsInList(int index) @@ -77,25 +84,22 @@ if (nowIndexOver != IndexOver) { - if (IndexOver.HasValue) RefreshItem(IndexOver.Value); IndexOver = nowIndexOver; - if (IndexOver.HasValue) RefreshItem(IndexOver.Value); + listBox.Invalidate(); } } - public void RenderToItem(DrawItemEventArgs e) + public void RenderToItem(int index, Graphics g) { using (Bitmap b = new Bitmap(Control.Size.Width, Control.Size.Height)) { - if (e.Index == IndexOver) + if (index == IndexOver) { Control.Hover(); } Control.DrawToBitmap(b, new Rectangle(new Point(), Control.Size)); - Point offsetLoc = e.Bounds.Location; - offsetLoc.Offset(Control.Location); - e.Graphics.DrawImage(b, offsetLoc.X, offsetLoc.Y); - if (e.Index == IndexOver) + g.DrawImage(b, Control.Location.X, Control.Location.Y); + if (index == IndexOver) { Control.Unhover(); } diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index d6d2006..3f482fe 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -29,21 +29,20 @@ private void InitializeComponent() { this.defaultShortcutLabel = new System.Windows.Forms.Label(); - this.entryListBox = new System.Windows.Forms.ListBox(); + this.entryListBox = new ListBoxEx(); this.createButton = new System.Windows.Forms.Button(); this.appUserModelIdLabel = new System.Windows.Forms.Label(); - this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); this.appButton = new System.Windows.Forms.Button(); this.hwndButton = new System.Windows.Forms.Button(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); this.SuspendLayout(); // // defaultShortcutLabel // this.defaultShortcutLabel.AutoSize = true; - this.defaultShortcutLabel.Location = new System.Drawing.Point(19, 94); - this.defaultShortcutLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); this.defaultShortcutLabel.Name = "defaultShortcutLabel"; - this.defaultShortcutLabel.Size = new System.Drawing.Size(226, 25); + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); this.defaultShortcutLabel.TabIndex = 0; this.defaultShortcutLabel.Text = "Select default shortcut"; // @@ -54,10 +53,9 @@ | System.Windows.Forms.AnchorStyles.Right))); this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(21, 122); - this.entryListBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(1025, 443); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); @@ -65,10 +63,9 @@ // createButton // this.createButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.createButton.Location = new System.Drawing.Point(859, 572); - this.createButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; - this.createButton.Size = new System.Drawing.Size(192, 50); + this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; @@ -76,32 +73,18 @@ // appUserModelIdLabel // this.appUserModelIdLabel.AutoSize = true; - this.appUserModelIdLabel.Location = new System.Drawing.Point(19, 15); - this.appUserModelIdLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); this.appUserModelIdLabel.Name = "appUserModelIdLabel"; - this.appUserModelIdLabel.Size = new System.Drawing.Size(284, 25); + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); this.appUserModelIdLabel.TabIndex = 3; this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; // - // appUserModelIdBox - // - this.appUserModelIdBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.appUserModelIdBox.Location = new System.Drawing.Point(21, 44); - this.appUserModelIdBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.appUserModelIdBox.Name = "appUserModelIdBox"; - this.appUserModelIdBox.Size = new System.Drawing.Size(809, 31); - this.appUserModelIdBox.TabIndex = 4; - this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; - this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; - // // appButton // this.appButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.appButton.Location = new System.Drawing.Point(844, 44); - this.appButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.appButton.Location = new System.Drawing.Point(633, 35); this.appButton.Name = "appButton"; - this.appButton.Size = new System.Drawing.Size(99, 39); + this.appButton.Size = new System.Drawing.Size(74, 31); this.appButton.TabIndex = 5; this.appButton.Text = "APP"; this.appButton.UseVisualStyleBackColor = true; @@ -110,22 +93,32 @@ // hwndButton // this.hwndButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.hwndButton.Location = new System.Drawing.Point(949, 44); - this.hwndButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.hwndButton.MinimumSize = new System.Drawing.Size(101, 32); + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); this.hwndButton.Name = "hwndButton"; - this.hwndButton.Size = new System.Drawing.Size(101, 39); + this.hwndButton.Size = new System.Drawing.Size(76, 31); this.hwndButton.TabIndex = 6; this.hwndButton.Text = "HWND"; this.hwndButton.UseVisualStyleBackColor = true; this.hwndButton.Click += new System.EventHandler(this.hwndButton_Click); // + // appUserModelIdBox + // + this.appUserModelIdBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // // MainForm // this.AcceptButton = this.createButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1067, 635); + this.ClientSize = new System.Drawing.Size(800, 508); this.Controls.Add(this.hwndButton); this.Controls.Add(this.appButton); this.Controls.Add(this.appUserModelIdBox); @@ -133,7 +126,6 @@ this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); this.Controls.Add(this.defaultShortcutLabel); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "MainForm"; this.Text = "Form1"; this.ResumeLayout(false); @@ -144,7 +136,7 @@ #endregion private System.Windows.Forms.Label defaultShortcutLabel; - private System.Windows.Forms.ListBox entryListBox; + private ListBoxEx entryListBox; private System.Windows.Forms.Button createButton; private System.Windows.Forms.Label appUserModelIdLabel; private System.Windows.Forms.Button appButton; diff --git a/ShortcutUtil/ListBoxButton.cs b/ShortcutUtil/ListBoxButton.cs old mode 100644 new mode 100755 index 46518cd..e5f6b49 --- a/ShortcutUtil/ListBoxButton.cs +++ b/ShortcutUtil/ListBoxButton.cs @@ -9,6 +9,28 @@ namespace ShortcutUtil { + public class ListBoxEx : ListBox + { + private bool designMode; + public ListBoxEx() : base() + { + designMode = System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime; + } + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + if (!designMode) + { + cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED + cp.Style &= ~0x040; // Turn off CS_CLASSDC + } + return cp; + } + } + } + public interface IListBoxControl { void Hover(); @@ -34,26 +56,11 @@ public int? IndexOver { get; private set; } - private MethodInfo refreshItem; public ListBoxControl(T control, ListBox listBox) { Control = control; this.listBox = listBox; listBox.MouseMove += ListBoxMouseMove; - - refreshItem = listBox.GetType().GetMethod("RefreshItem", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(int) }, null); - } - - private void RefreshItem(int index) - { - listBox.BeginUpdate(); - object item = listBox.Items[index]; - listBox.Items.RemoveAt(index); - listBox.Items.Insert(index, item); - listBox.EndUpdate(); - //listBox.Items[index] = item; - //listBox.Items[index] = - //if (refreshItem != null) refreshItem.Invoke(listBox, new object[] { index }); } public Rectangle BoundsInList(int index) @@ -77,25 +84,22 @@ if (nowIndexOver != IndexOver) { - if (IndexOver.HasValue) RefreshItem(IndexOver.Value); IndexOver = nowIndexOver; - if (IndexOver.HasValue) RefreshItem(IndexOver.Value); + listBox.Invalidate(); } } - public void RenderToItem(DrawItemEventArgs e) + public void RenderToItem(int index, Graphics g) { using (Bitmap b = new Bitmap(Control.Size.Width, Control.Size.Height)) { - if (e.Index == IndexOver) + if (index == IndexOver) { Control.Hover(); } Control.DrawToBitmap(b, new Rectangle(new Point(), Control.Size)); - Point offsetLoc = e.Bounds.Location; - offsetLoc.Offset(Control.Location); - e.Graphics.DrawImage(b, offsetLoc.X, offsetLoc.Y); - if (e.Index == IndexOver) + g.DrawImage(b, Control.Location.X, Control.Location.Y); + if (index == IndexOver) { Control.Unhover(); } diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index d6d2006..3f482fe 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -29,21 +29,20 @@ private void InitializeComponent() { this.defaultShortcutLabel = new System.Windows.Forms.Label(); - this.entryListBox = new System.Windows.Forms.ListBox(); + this.entryListBox = new ListBoxEx(); this.createButton = new System.Windows.Forms.Button(); this.appUserModelIdLabel = new System.Windows.Forms.Label(); - this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); this.appButton = new System.Windows.Forms.Button(); this.hwndButton = new System.Windows.Forms.Button(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); this.SuspendLayout(); // // defaultShortcutLabel // this.defaultShortcutLabel.AutoSize = true; - this.defaultShortcutLabel.Location = new System.Drawing.Point(19, 94); - this.defaultShortcutLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); this.defaultShortcutLabel.Name = "defaultShortcutLabel"; - this.defaultShortcutLabel.Size = new System.Drawing.Size(226, 25); + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); this.defaultShortcutLabel.TabIndex = 0; this.defaultShortcutLabel.Text = "Select default shortcut"; // @@ -54,10 +53,9 @@ | System.Windows.Forms.AnchorStyles.Right))); this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(21, 122); - this.entryListBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(1025, 443); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); @@ -65,10 +63,9 @@ // createButton // this.createButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.createButton.Location = new System.Drawing.Point(859, 572); - this.createButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; - this.createButton.Size = new System.Drawing.Size(192, 50); + this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; @@ -76,32 +73,18 @@ // appUserModelIdLabel // this.appUserModelIdLabel.AutoSize = true; - this.appUserModelIdLabel.Location = new System.Drawing.Point(19, 15); - this.appUserModelIdLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); this.appUserModelIdLabel.Name = "appUserModelIdLabel"; - this.appUserModelIdLabel.Size = new System.Drawing.Size(284, 25); + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); this.appUserModelIdLabel.TabIndex = 3; this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; // - // appUserModelIdBox - // - this.appUserModelIdBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.appUserModelIdBox.Location = new System.Drawing.Point(21, 44); - this.appUserModelIdBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.appUserModelIdBox.Name = "appUserModelIdBox"; - this.appUserModelIdBox.Size = new System.Drawing.Size(809, 31); - this.appUserModelIdBox.TabIndex = 4; - this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; - this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; - // // appButton // this.appButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.appButton.Location = new System.Drawing.Point(844, 44); - this.appButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.appButton.Location = new System.Drawing.Point(633, 35); this.appButton.Name = "appButton"; - this.appButton.Size = new System.Drawing.Size(99, 39); + this.appButton.Size = new System.Drawing.Size(74, 31); this.appButton.TabIndex = 5; this.appButton.Text = "APP"; this.appButton.UseVisualStyleBackColor = true; @@ -110,22 +93,32 @@ // hwndButton // this.hwndButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.hwndButton.Location = new System.Drawing.Point(949, 44); - this.hwndButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.hwndButton.MinimumSize = new System.Drawing.Size(101, 32); + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); this.hwndButton.Name = "hwndButton"; - this.hwndButton.Size = new System.Drawing.Size(101, 39); + this.hwndButton.Size = new System.Drawing.Size(76, 31); this.hwndButton.TabIndex = 6; this.hwndButton.Text = "HWND"; this.hwndButton.UseVisualStyleBackColor = true; this.hwndButton.Click += new System.EventHandler(this.hwndButton_Click); // + // appUserModelIdBox + // + this.appUserModelIdBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // // MainForm // this.AcceptButton = this.createButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1067, 635); + this.ClientSize = new System.Drawing.Size(800, 508); this.Controls.Add(this.hwndButton); this.Controls.Add(this.appButton); this.Controls.Add(this.appUserModelIdBox); @@ -133,7 +126,6 @@ this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); this.Controls.Add(this.defaultShortcutLabel); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "MainForm"; this.Text = "Form1"; this.ResumeLayout(false); @@ -144,7 +136,7 @@ #endregion private System.Windows.Forms.Label defaultShortcutLabel; - private System.Windows.Forms.ListBox entryListBox; + private ListBoxEx entryListBox; private System.Windows.Forms.Button createButton; private System.Windows.Forms.Label appUserModelIdLabel; private System.Windows.Forms.Button appButton; diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index ccd2997..a336e63 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -20,6 +20,19 @@ { public partial class MainForm : Form { + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + if (!designMode) + { + cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED + } + return cp; + } + } + private EntryList entryList; private Font defaultFont; @@ -30,8 +43,13 @@ private EntryListItem listLayout; + private bool designMode; + public MainForm(EntryList entryList, AppResolver appResolver) { + designMode = System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime; + + InitializeComponent(); typeof(ListBox).InvokeMember("DoubleBuffered", @@ -110,37 +128,55 @@ private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) { - e.DrawBackground(); - e.DrawFocusRectangle(); + int index = e.Index; - listLayout.LayoutFromList(); + //RectangleF baseRectF = new RectangleF(new PointF(), e.Bounds.Size); + Rectangle baseRect = new Rectangle(new Point(), e.Bounds.Size); - if (e.Index >= 0 && e.Index < entryList.Entries.Count) + using (Bitmap b = new Bitmap(baseRect.Width, baseRect.Height)) { - Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + Graphics g = Graphics.FromImage(b); - Size textSize = new Size(0, nameFont.Height + 2); + Brush backBrush = new SolidBrush(e.BackColor); + g.FillRectangle(backBrush, baseRect); + backBrush.Dispose(); - Entry entry = entryList.Entries[e.Index]; + if ((e.State & DrawItemState.Focus) == DrawItemState.Focus + && (e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect) + ControlPaint.DrawFocusRectangle(g, baseRect, ForeColor, BackColor); - Icon icon = GetIcon(entry.Icon, entry.IconIndex, IconSize); - if (icon != null) + listLayout.LayoutFromList(); + + if (index >= 0 && index < entryList.Entries.Count) { - e.Graphics.DrawIcon(icon, iconBounds); + Rectangle iconBounds = new Rectangle(new Point(ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[index]; + + Icon icon = GetIcon(entry.Icon, entry.IconIndex, IconSize); + if (icon != null) + { + g.DrawIcon(icon, iconBounds); + } + + PointF textLocation = new PointF(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width); + + g.DrawString(index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + g.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + g.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + listLayout.TestButton.RenderToItem(index, g); } - PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); - e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); - textLocation = PointF.Add(textLocation, textSize); - - e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); - textLocation = PointF.Add(textLocation, textSize); - - e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); - textLocation = PointF.Add(textLocation, textSize); - - listLayout.TestButton.RenderToItem(e); + e.Graphics.DrawImage(b, e.Bounds.Location); } }