Make a MenuStrip Category Item
All tutorials created in C# to be posted in here.
2 posts
Page 1 of 1
In this tutorial you will learn how to make a MenuStrip Category Item like the one in the picture bellow.
CCategoryItem
Now add this Namespaces and Inherit ToolStripMenuItem
Constructor
Background
This code is all written by me you can use it or modify it anyway you want. Please don't share it on other websites as your own.
First start by creating a new class named Now add this Namespaces and Inherit ToolStripMenuItem
Code: Select all
Next we must write the Constructor and Propertiesusing System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
Constructor
Code: Select all
Properties
#region Constructor
public CCategoryItem()
{
this.AutoSize = false;
this.Dock = DockStyle.Fill;
this.Font = new Font("Arial", 8, FontStyle.Bold);
}
#endregion
Code: Select all
Now the Drawing begins. First we must draw the Background and then the Text#region Properties
//Logic
public override bool CanSelect
{
get
{
return false;
}
}
//Colors
private Color _BackgroundColor = Color.FromArgb(236, 241, 247);
public Color BackgroundColor
{
get { return _BackgroundColor; }
set { _BackgroundColor = value; this.Invalidate(); }
}
private Color _BorderColor = Color.FromArgb(209, 208, 206);
public Color BorderColor
{
get { return _BorderColor; }
set { _BorderColor = value; this.Invalidate(); }
}
private Color _TextColor = Color.FromArgb(39, 72, 103);
public Color TextColor
{
get { return _TextColor; }
set { _TextColor = value; this.Invalidate(); }
}
#endregion
Background
Code: Select all
Text
#region Draw Background
private void DrawCategoryBackground(Graphics e)
{
//Get Rectangle
Rectangle _ItemRect = new Rectangle(0, 0, this.Width, this.Height);
//Draw
using (SolidBrush _BackgroundBrush = new SolidBrush(_BackgroundColor))
using (Pen _BorderPen = new Pen(_BorderColor))
{
//Draw Background
e.FillRectangle(_BackgroundBrush, _ItemRect);
//Draw Border
e.DrawLine(_BorderPen, _ItemRect.X, _ItemRect.Height - 1, _ItemRect.X + _ItemRect.Width, _ItemRect.Height - 1);
}
}
#endregion
Code: Select all
And finally override the System Paint
#region Draw Text
private void DrawCategoryText(Graphics e)
{
//Get Text Size
Size _TextSize = e.MeasureString(this.Text, this.Font).ToSize();
//Draw
using (SolidBrush _TextBrush = new SolidBrush(_TextColor))
{
//Draw Text
e.DrawString(this.Text, this.Font, _TextBrush, 2, this.Height / 2 - _TextSize.Height / 2 - 1);
}
}
#endregion
Code: Select all
That's it we're finished. I hope you like this tutorial. #region Override System Paint
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e); //Ignore System Paint
DrawCategoryBackground(e.Graphics);
DrawCategoryText(e.Graphics);
}
#endregion
This code is all written by me you can use it or modify it anyway you want. Please don't share it on other websites as your own.
You do not have the required permissions to view the files attached to this post.
You can find me on Facebook or on Skype mihai_92b
nice work
love it
love it
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023