Click here to Skip to main content
Licence 
First Posted 3 Sep 2007
Views 12,169
Downloads 134
Bookmarked 10 times

MenuItem with Icon_Circle Button

By | 3 Sep 2007 | Article
Creating MenuItem with Icon _ Creating Circle Button
Screenshot - Demo_image.jpg

Introduction

Normal when creating Form with C# using Toolbox of VS.NET, you can't create Menu Item with Icon whether that is a really require. I researched and developed this application for this problem

Using MenuItem with Icon _ CircleButton, you can creating MenuItem with Icon which attrachtive, therefor, i created Custom Button using Drawing

Background

VS.NET 2003

Using the code

<code>

protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
Brush br; // using for paint rectangle

Rectangle rcBk = e.Bounds;
// add Width of Icon Image
rcBk.X -= m_Icon.Width;
rcBk.Width += m_Icon.Width;

// When menu item is Enabled
if((e.State & DrawItemState.Selected) != 0 && this.Enabled == true)
{ // When selected (highlighted)
float f = 0;
br = new LinearGradientBrush(rcBk, m_Gradient_Color1, m_Gradient_Color2, f);
//Paint main rectangle
e.Graphics.FillRectangle(br, rcBk);

//Paint Border for main rectangle
Pen pen = new Pen(new SolidBrush(SystemColors.Highlight));
e.Graphics.DrawRectangle(pen, e.Bounds.Left, e.Bounds.Top, rcBk.Width - 17, rcBk.Height-1);
}
else // When not selected
{
//Paint main rectangle
br = new SolidBrush( SystemColors.Menu ) ;
e.Graphics.FillRectangle(br, rcBk);
//Paint background rectangle for Icon
br = new SolidBrush( SystemColors.Control ) ;
e.Graphics.FillRectangle(br, e.Bounds.Left, e.Bounds.Top, m_Icon.Width + 6, m_Icon.Height + 6);
}

//Paint Icon front of main rectangle
if(m_Icon != null)
{
e.Graphics.DrawIcon(m_Icon, e.Bounds.Left + 2, e.Bounds.Top + 3);
}
StringFormat sf = new StringFormat();
sf.HotkeyPrefix = HotkeyPrefix.Show;

// Set text color
if ( this.Enabled == false ) // When menu item is not enabled
{
br = new SolidBrush( SystemColors.GrayText ) ;
}
else
{
br = new SolidBrush( SystemColors.WindowText ) ;
// br = new SolidBrush(e.ForeColor);
}

//Paint text
e.Graphics.DrawString(GetRealText(), m_Font, br, e.Bounds.Left + 25, e.Bounds.Top + 2, sf);
}

</code>

Points of Interest

No Problem

History

It is first version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

aiglevn

Software Developer

Vietnam Vietnam

Member

I am from Vietnam and I love IT (^_^)
 
.....::::: A I G L E V N :::::.....

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionwrong place? PinmemberNGS 5496725:45 4 Sep '07  
GeneralReformat the article PinmemberSudhir Mangla2:51 4 Sep '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 4 Sep 2007
Article Copyright 2007 by aiglevn
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid