Windows Develop Bookmark and Share   
 index > Windows Forms General > How to remove the margin of a menu using C#
 

How to remove the margin of a menu using C#

I want to display a control on the context menu using ToolStripControlHost. But, margins, such as an icon area, occur in following codes. Even if I specify Padding, Margin, etc. as 0, a margin remains. Aren't there any good ideas?

ContextMenuStrip cms = new ContextMenuStrip();
cms.ShowCheckMargin = false;
cms.ShowImageMargin = false;
cms.AutoSize = false;
ExtraControl esc = new ExtraControl();
cms.Items.Add(new ToolStripControlHost(esc));
cms.ClientSize = new Size(esc.Size.Width, esc.Size.Height);
cms.Padding = new Padding(0);
cms.Margin = new Padding(0);
cms.Show(e.Location);
Tank2005  Thursday, October 01, 2009 6:09 AM

Hi,

 

Sorry, I test on my side. Unfortunately, I am not able to reproduce. Items still don’t show CheckMargin and ImageMargn.

Could you please provide more details or make a demo project for us to test? Please upload your demo project to some server and offer us the URL.  Skydrive (http://skydrive.live.com/ ) may be a good option. You can sign up 25GB free space only with your Windows Live Passport.

I use the following code;

        private void button1_Click(object sender, EventArgs e)

        {

            ContextMenuStrip cms = new ContextMenuStrip();

            cms.ShowCheckMargin = false;

            cms.ShowImageMargin = false;

            cms.AutoSize = false;

            TextBox textbox1 = new TextBox();

            textbox1.Text = "11111111111111111111";

 

            //ExtraControl esc = new ExtraControl();

            cms.Items.Add(new ToolStripControlHost(textbox1));

            cms.ClientSize = new Size(500,500);

            cms.Padding = new Padding(0);

            cms.Margin = new Padding(0);

            cms.Items.Add("aaaaaaaaaaaaa", Image.FromFile(@"C:\Users\##\Desktop\test.jpg"));

            cms.Show(this.Location);

        }

 


Best regards,

Ling Wang


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Wednesday, October 07, 2009 8:11 AM
Thank you for your reply.

A sample project is here. Because my development environment is Windows Vista, Visual Style may have influenced.

http://cid-74eabb0e82700b4d.s kydrive.live.com/self.aspx/%e5%85%ac%e9%96%8b/ContextMenuTest.zip
Tank2005  Wednesday, October 07, 2009 3:00 PM
Don't turn off AutoSize or set the ClientSize, that will crash it by itself if you click the scroll arrows you get.  Are you talking about the gap on the right?  I repro that, not a gap on the left.

Hans Passant.
nobugz  Wednesday, October 07, 2009 7:48 PM

You can use google to search for other answers

Custom Search

More Threads

• data reading and writing.
• Problem with the splitcontainer control
• .net equivalent of Printer.Print easy function
• Detecting Message Boxes and close them automaticaly.
• Updating Controls in MultiThreading
• how to tell when a UserControl is going away (removed from form or form closing)?
• Howto: expose the Items property of a MenuStrip as a property of a class containing the MenuStrip(with designer support)
• How to pass VBA Collection to COM DLL from .NET C#?
• newbie question: capturing right click events in vb.net
• Tab Key is not tapped!