views:

50

answers:

2

I'm using WinForms : C# .NET.

I'm facing a problem with ContextMenuStrip and Toolstrip. Visual Stuido's Property editor is not letting me to change the property I want.

Here is the snapshot of how I want my ContextMenuStrip to looklike & same is the case with Toolstrip. I don't understand how to do this.

If I need to learn something, please suggest appropriate good material (tutorials, articles etc.)

alt text

+1  A: 

There is no single property that you can set to make a ContextMenuStrip look like that.

You need to create your own ToolStripRenderer class that paints menus like that, then set the Renderer property of the ContextMenuStrip to an instance of your ToolStripRenderer.

Good luck.

EDIT: You can find sample code here.

SLaks
claws
No; only ToolStrip. You can paint the titlebar your self by overriding WndProc and handling the WM_NCPAINT message. http://msdn.microsoft.com/en-us/library/dd145212%28VS.85%29.aspx.
SLaks
You should probably switch to a component suite with built-in skinning support; it will be _much much_ easier than doing it yourself. I recommend DevExpress. http://www.devexpress.com/Products/NET/Controls/WinForms/Skins/
SLaks
This seems to be WIN32API. I'm using .NET. :(
claws
claws
+2  A: 

You'll have to assign the Renderer property to a class that renders the CMS or tool strip the way you want it. Use this code as a template to get started:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        contextMenuStrip1.Renderer = new myRenderer();
    }
    class myRenderer : ToolStripProfessionalRenderer {
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) {
            // Replace this with your own drawing code...
            base.OnRenderToolStripBackground(e);
        }
    }
}
Hans Passant
Thanks, I want to know whenever you guys give the sample code. Do you guys code it for the answer or It will be from your previous work?
claws
I know that your are a MVP
claws
Don't hold it against me, please. I typed it in 10 minutes ago to make sure it compiled.
Hans Passant
I really appreciate when people give some sample code. Thank you. :)
claws