Click here to Skip to main content
15,890,123 members
Home / Discussions / C#
   

C#

 
GeneralRe: Delete FileDialog Pin
anatsg14-Jun-04 9:11
anatsg14-Jun-04 9:11 
Generalsome int16[ ] arrays: OutOfMemoryException Pin
noizy13-Jun-04 7:39
noizy13-Jun-04 7:39 
GeneralRe: some int16[ ] arrays: OutOfMemoryException Pin
Colin Angus Mackay13-Jun-04 12:52
Colin Angus Mackay13-Jun-04 12:52 
GeneralMenu Images in ContextMenu Pin
gek_at13-Jun-04 7:13
gek_at13-Jun-04 7:13 
GeneralRe: Menu Images in ContextMenu Pin
Mazdak13-Jun-04 7:27
Mazdak13-Jun-04 7:27 
GeneralRe: Menu Images in ContextMenu Pin
gek_at13-Jun-04 7:34
gek_at13-Jun-04 7:34 
GeneralRe: Menu Images in ContextMenu Pin
leppie13-Jun-04 10:20
leppie13-Jun-04 10:20 
GeneralRe: Menu Images in ContextMenu Pin
gek_at13-Jun-04 11:43
gek_at13-Jun-04 11:43 
Hi!

Thanks for your anwer. I did something similar like in this article. The comment there points to the MS bug report, hence I thought it might cause the problem.

Here's my MenuItem Subclass. It's based on the Dr. GUI article from here.

<br />
<br />
using System;<br />
using System.Drawing;<br />
using System.Drawing.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace SharpPrivacy.SharpPrivacyTray {<br />
	<br />
System.Windows.Forms.MenuItem {<br />
  private Icon icon;<br />
  private Font font;<br />
		<br />
  public ImageMenuItem(string text) : this(null, text) {}<br />
		<br />
  public ImageMenuItem(Icon icon) : this(icon, "") {}<br />
		<br />
  public ImageMenuItem(Icon icon, string text) : base(text) {<br />
   makeReady(icon);<br />
  }<br />
		<br />
  public ImageMenuItem(Icon icon, string text, EventHandler onClick) : base(text, onClick) {<br />
   makeReady(icon);<br />
  }<br />
		<br />
  public ImageMenuItem(Icon icon, string text, MenuItem[] items) : bas  e(text, items) {<br />
 makeReady(icon);<br />
  }<br />
		<br />
  public ImageMenuItem(Icon icon, string text, EventHandler onClick, Shortcut shortcut) : base(text, onClick, shortcut) {<br />
   makeReady(icon);<br />
  }<br />
		<br />
  public ImageMenuItem(Icon icon, MenuMerge mergeType, int mergeOrder, Shortcut shortcut, string text, EventHandler onClick, EventHandler onPopup, EventHandler onSelect, MenuItem[] items) : base(mergeType, mergeOrder, shortcut, text, onClick, onPopup, onSelect, items) {<br />
   makeReady(icon);<br />
  }<br />
		<br />
  private void makeReady(Icon icon) {<br />
   this.OwnerDraw = true;<br />
   this.font = SystemInformation.MenuFont;<br />
   this.icon = icon;<br />
  }<br />
		<br />
  public void addIcon(Icon icon) {<br />
   this.icon = icon;<br />
  }<br />
		<br />
  protected override void OnMeasureItem(MeasureItemEventArgs e) {<br />
   base.OnMeasureItem(e);<br />
			<br />
   StringFormat sf = new StringFormat();<br />
			<br />
   sf.HotkeyPrefix = HotkeyPrefix.Show;<br />
   sf.SetTabStops(50, new Single[] {0});<br />
			<br />
   if (icon.Height > font.Height) {<br />
    e.ItemHeight = icon.Height + 6;<br />
   } else {<br />
    e.ItemHeight = font.Height + 6;<br />
   }<br />
			<br />
   e.ItemWidth = (int)((e.Graphics.MeasureString(AppendShortcut(), font, 1000, sf).Width) + icon.Width + 5);<br />
   sf.Dispose();<br />
  }<br />
		<br />
  protected override void OnDrawItem(DrawItemEventArgs e) {<br />
   Brush br;<br />
   StringFormat sf;<br />
			<br />
   base.OnDrawItem(e);<br />
   e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds);<br />
   if (this.icon != null) {<br />
    e.Graphics.DrawIcon(this.icon, e.Bounds.Left + 3, e.Bounds.Top + 3);<br />
   }<br />
			<br />
   sf = new StringFormat();<br />
   sf.HotkeyPrefix = HotkeyPrefix.Show;<br />
   sf.SetTabStops(50, new Single[] {0});<br />
   br = new SolidBrush(SystemColors.WindowText);<br />
   e.Graphics.DrawString(AppendShortcut(), this.font, br, e.Bounds.Left + this.icon.Width + 10, e.Bounds.Top + 2, sf);<br />
			<br />
   br.Dispose();<br />
   sf.Dispose();<br />
  }<br />
		<br />
  private string AppendShortcut() {<br />
   String s;<br />
   s = this.Text;<br />
			<br />
   if (this.ShowShortcut && (this.Shortcut != Shortcut.None)) {<br />
    Keys k = (Keys)Shortcut;<br />
    s = s + Convert.ToChar(9) + System.ComponentModel.TypeDescriptor.GetConverter(k.GetType()).ConvertToString(k);<br />
   }<br />
   return s;<br />
  }<br />
		<br />
		<br />
 }<br />
}<br />
<br />


I use the contextmenu together with a tray icon. perhaps thats the problem?

TIA,
Daniel

---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
GeneralRe: Menu Images in ContextMenu Pin
gek_at13-Jun-04 11:59
gek_at13-Jun-04 11:59 
GeneralRe: Menu Images in ContextMenu Pin
leppie13-Jun-04 12:19
leppie13-Jun-04 12:19 
GeneralRe: Menu Images in ContextMenu Pin
gek_at13-Jun-04 23:20
gek_at13-Jun-04 23:20 
GeneralRe: Menu Images in ContextMenu Pin
leppie13-Jun-04 12:02
leppie13-Jun-04 12:02 
General&quot;an error occurred while loading the document&quot; Pin
enduro1x13-Jun-04 6:35
enduro1x13-Jun-04 6:35 
GeneralRe: &quot;an error occurred while loading the document&quot; Pin
leppie13-Jun-04 6:59
leppie13-Jun-04 6:59 
GeneralRe: &quot;an error occurred while loading the document&quot; Pin
enduro1x13-Jun-04 7:04
enduro1x13-Jun-04 7:04 
GeneralOemToAnsi in C# Pin
brunoskorepa13-Jun-04 6:24
brunoskorepa13-Jun-04 6:24 
GeneralRe: OemToAnsi in C# Pin
Colin Angus Mackay13-Jun-04 6:27
Colin Angus Mackay13-Jun-04 6:27 
Generalslow performance of C# windows form program Pin
vcorn13-Jun-04 6:05
vcorn13-Jun-04 6:05 
GeneralRe: slow performance of C# windows form program Pin
Colin Angus Mackay13-Jun-04 6:22
Colin Angus Mackay13-Jun-04 6:22 
GeneralRe: slow performance of C# windows form program Pin
vcorn13-Jun-04 7:03
vcorn13-Jun-04 7:03 
Generaldescription and intellisense Pin
amatyasik13-Jun-04 3:29
amatyasik13-Jun-04 3:29 
GeneralRe: description and intellisense Pin
mikker_12313-Jun-04 3:48
mikker_12313-Jun-04 3:48 
GeneralRe: description and intellisense Pin
Stefan Troschuetz13-Jun-04 3:56
Stefan Troschuetz13-Jun-04 3:56 
GeneralRe: description and intellisense Pin
amatyasik13-Jun-04 4:37
amatyasik13-Jun-04 4:37 
GeneralA popup button without border Pin
zlaty12-Jun-04 23:07
zlaty12-Jun-04 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.