Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,690 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,316 people online right now. Registration is fast and FREE... Join Now!




Removing image from ToolStripMenuItem

 
Reply to this topicStart new topic

Removing image from ToolStripMenuItem

cygnusX
post 2 Jun, 2008 - 09:10 AM
Post #1


D.I.C Head

**
Joined: 19 May, 2007
Posts: 159


My Contributions


I want to remove the image from ToolStripMenuItem but i can't.I set the DisplayStyle to 'Text' but nothing happens.The blank space before the text remains visible.I tried to create custom ToolStripMenuItem class.Inside that class i tried to override the OnPaint method and it works fine but for some unknown reason i cannot override the OnMouseEnter method and when moving the mouse cursor over the items their color is not changed and it's hard to see which item has the focus in certain moment.So,how to remove that blank space which represents the image?Thanks in advance.
User is offlineProfile CardPM

Go to the top of the page

djkitt
post 2 Jun, 2008 - 10:02 AM
Post #2


D.I.C Head

**
Joined: 22 May, 2008
Posts: 128



Thanked 13 times
My Contributions


Well...

This isn't exactly what you are looking for, I am sure. But... You can make images of all your Menu Item Text and then set your properties to:

DisplayStyle - Image
ImageScaling - None

Its kind of an involved process, but it does work.


User is offlineProfile CardPM

Go to the top of the page

cygnusX
post 3 Jun, 2008 - 08:42 AM
Post #3


D.I.C Head

**
Joined: 19 May, 2007
Posts: 159


My Contributions


It doesn't work for me because the text values for the menu items are not constants.They can be changed during the runtime.Thanks anyway.
User is offlineProfile CardPM

Go to the top of the page

djkitt
post 3 Jun, 2008 - 10:46 AM
Post #4


D.I.C Head

**
Joined: 22 May, 2008
Posts: 128



Thanked 13 times
My Contributions


OK.

How about using Graphics.Drawstring to create the image at load time and then recreate it if the text changes.

I like this better anyway as it is *not* an involved process.

CODE

.
.
.
            toolStripMenuItem1.Image = drawText(toolStripMenuItem1.Text);
.
.
.


        public Bitmap drawText(string text)
        {
            Bitmap b = new Bitmap(1, 1);

            int width = 0;
            int height = 0;

            Font font = new Font("Arial", 12, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
            Graphics g = Graphics.FromImage(b);

            width = (int)g.MeasureString(text, font).Width;
            height = (int)g.MeasureString(text, font).Height;

            b=new Bitmap(b, new Size(width, height));
            g = Graphics.FromImage(b);
            g.Clear(Color.Transparent);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            g.DrawString(text, font, new SolidBrush(SystemColors.WindowText),0,0);
            g.Flush();
            return b;
        }


I grabbed the drawText routine from:
http://chiragrdarji.wordpress.com/2008/05/...-image-using-c/

I tested it and it seems to work in my admittedly limited prog.

User is offlineProfile CardPM

Go to the top of the page

cygnusX
post 3 Jun, 2008 - 11:29 AM
Post #5


D.I.C Head

**
Joined: 19 May, 2007
Posts: 159


My Contributions


Ok,thank you.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:38AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month