View Single Post
Old June 22nd, 2009   #26 (permalink)
S.T.A.R.S.
 
S.T.A.R.S.'s Avatar
 
Join Date: Jan 2006
Location: Planet Earth...
Posts: 593
I am the happiest man on the world!!!I wrote the code,(with a help from the internet),with which I have successfuly changed the back and fore color for mouse leave and mouse enter(hover)!!!The code works perfect!
I read what you said and I used those 2 events: DrawItem and MeasureItem.I wrote the cfode for both of them and everything works like charm.Here is the entire code:

privatevoid menuItem1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Rectangle rc=
new Rectangle(e.Bounds.X,e.Bounds.Y,e.Bounds.Width,e.B ounds.Height);
e.Graphics.FillRectangle(
new SolidBrush(Color.Black),rc);
MenuItem s=(MenuItem)sender;
string s1=s.Text;
StringFormat sf=
new StringFormat();
sf.Alignment=StringAlignment.Near;
sf.LineAlignment=StringAlignment.Center;
Rectangle rcText=rc;
rcText.Width+=5;
e.Graphics.DrawString(s1,
new Font("Verdana",10),new SolidBrush(Color.Blue),rcText,sf);
if(e.State==(DrawItemState.NoAccelerator|DrawItemSta te.Selected))
{
e.Graphics.FillRectangle(
new SolidBrush(Color.Yellow),rc);
}
if(e.State==(DrawItemState.NoAccelerator|DrawItemSta te.Selected))
{
e.Graphics.DrawString(s1,
new Font("Verdana",10),new SolidBrush(Color.Red),rcText,sf);
}
}
privatevoid menuItem1_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
{
e.ItemWidth=75;
e.ItemHeight=20;
}

I think this code is pretty goodI will now try to make letters to be bold,change their size and see will I make it...
If I do,I will give you the code.

By the way...this is EXACTLY why I use Visual C# 2002.If I was using Visual C# 2005 or 2008,I would never learn this because I would be simply doing this in the properties window.In Visual C# 2002 with the .NET 1.0 I need to create my own and that is exactly what I want.
__________________
GOODBYE FOREVER EVERYONE...
S.T.A.R.S. is offline   Reply With Quote