|
|
Unfortunatly it does not. The Microsoft link I added describes a .net bug that makes it impossible to set OwnerDraw true in ContextMenu instances. The article works fine for main menus, but not for context menues.
Thanks anyway,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
gek_at wrote:
I tried all day long, just to discover http://support.microsoft.com/?id=827043.
That is a very specific condition, not even relating to images, but menuitems disappearing from the contextmenu. From your question it appears you have a more general problem. I use my ownerdrawn menuitems interchangebly between a mainmenu and a contextmenu and havent had such problems.
Perhaps describing your problem in more detail would be helpful, then we could help you perhaps, but a bunny rabbit came to me in a dream and tells me you didnt multiply the height of the menuitem with item index, and hence your offsets are wrong in the DrawItem event.
top secret xacc-ide 0.0.1
|
|
|
|
|
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
|
|
|
|
|
Hi again!
Here's some more sample code that shows the problem (where ImageMenuItem is used):
<br />
using System;<br />
<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
using System.Reflection;<br />
<br />
<br />
namespace SharpPrivacy.SharpPrivacyTray {<br />
class MenuTest : System.Windows.Forms.Form {<br />
<br />
private NotifyIcon niTrayIcon = new NotifyIcon();<br />
private ContextMenu cmnuTrayMenu = new ContextMenu();<br />
<br />
private ImageMenuItem mnuTest1 = new ImageMenuItem("Test1");<br />
private MenuItem mnuTest2 = new MenuItem("Test2");<br />
<br />
public MenuTest() {<br />
System.Resources.ResourceManager resources = new System.Resources.ResourceManager("SharpPrivacyTray", Assembly.GetExecutingAssembly()); <br />
<br />
Icon iTrayIcon = (System.Drawing.Icon)resources.GetObject("trayIcon");<br />
this.Icon = iTrayIcon;<br />
niTrayIcon.Icon = iTrayIcon;<br />
niTrayIcon.Visible = true;<br />
<br />
this.ShowInTaskbar = false;<br />
<br />
this.WindowState = FormWindowState.Minimized; <br />
this.ResumeLayout(false);<br />
<br />
mnuTest1.addIcon(((System.Drawing.Icon)resources.GetObject("menuClipboard")));<br />
<br />
cmnuTrayMenu.MenuItems.Add(mnuTest1);<br />
cmnuTrayMenu.MenuItems.Add(mnuTest2);<br />
niTrayIcon.ContextMenu = cmnuTrayMenu;<br />
<br />
<br />
}<br />
<br />
[STAThread]<br />
public static void Main(string[] args) {<br />
Application.Run(new MenuTest());<br />
}<br />
}<br />
}<br />
Greetings,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
IIRC i recall something about this happening because the way it create handles. What happens here is the handle of the form is destroyed and hence the commands probably dont reach them.
top secret xacc-ide 0.0.1
|
|
|
|
|
Hi!
Is there any chance of a workaround?
Thanks,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
The only remarkable differences i can see between my version and yours is:
a) I use Image contained in an ImageList.
b) I dont call the base class when overriding those to methods for very specific reasons, namely this prevents someone from "altering" the gfx from an event as the event will not be generated, and secondly, it prevents windows from doing something it shouldnt (u know that WTF? moments). Sometimes as with some methods the base methods should be called.
top secret xacc-ide 0.0.1
|
|
|
|
|
Hi
when I try to go in designer mode. I get an error it says:"An exception occurred while trying to create an instance of 'MyMainClassName'. The exception was "Constructor on type 'MyMainClassName' not found.
My class has the constructor.
I rebuild the project, but nothing is changed.
Please could you tell me what the problem is?
|
|
|
|
|
The designer expects a default constructor iow one without any paramters.
I was in fact writing this just 2 minutes ago:
throw new Exception(string.Format("default constructor expected on {0}", ppa.Type));
top secret xacc-ide 0.0.1
|
|
|
|
|
|
How can I convert a string that contains Ascii-characters to ANSI? In the Windows API there is a function OemToAnsi. How would I do this in C#/.NET?
thanks, Bruno
|
|
|
|
|
|
hi all, i just want to ask for suggestion
i create a windows form program mainform.cs, and in this mainform i created instance of all classes that will be used.
then i have another form that will only be created when user click a button on mainform.
the second form itself have some functionality, when user click on button, it will call a function.
I found doin this(multiple forms) slow down my program 100% instead of just using one mainform and call the function when user click on the button of the mainform directly.
If this is true that C# windows form very slow when i did this, it's very bad right?
i used to program with multiple java frame(window) and it doesn't matter at all.
Is there something wrong i did?
|
|
|
|
|
vcorn wrote:
Is there something wrong i did?
It sounds like it because I've never had any slow down in speed when dealing with one, two or more forms.
Can you describe more accrurately what you are trying to do, because I can't work out what you're doing to get it to slow down.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
i feel weird too,
it's basically just call a function of an object when user click on a button.
indeed this function deal with active directory(creating user in active directory).
when i switch to call this function from mainform button, it execute just well.
but when i change it to call this function from the second form(show as dialog with mainform as parent), it slow down, i have to wait 2-3 minutes to get it finish executing creating a user.
so i think there is nothing wrong in the code that slow down the performance,am i right?
|
|
|
|
|
Hi.
I search to add descriptions into the "intellisense" when i wrote a class or functon etc...
Thanks a lot
Alex
|
|
|
|
|
Check the following lines before class definition and chage it to meet your needs:
public class Info ..........
|
|
|
|
|
Use the various XML documentation tags to document your source code.
See the help for "XML documentation" for more information on this topic.
www.troschuetz.de
|
|
|
|
|
thanks to all
it's exactly what i search
|
|
|
|
|
How kan I make a button without borders that popups?
I kan make popup button but when the mouse isn't
over, the button still have border.
|
|
|
|
|
|
Thank you very much!
Is it not possible to be made directly in C#
without a class in C++?
|
|
|
|
|
Yes, but the concepts are usually the same. Almost every Windows Forms control (including the Button ) merely encapsulates the Windows Common Controls, so what's possible when handling messages is the way it's typically done in .NET (taking into account, of course, that much functionality is already exposed in methods, properties, and events - so don't redo what's already been done).
If you search CodeProject for buttons in the C# and .NET categories, you're bound to find a better example of this.
Also, read about the Button.FlatStyle property (inheritted from ButtonBase ) in the .NET Framework SDK to see if that will do what you need.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you very much ))
|
|
|
|