DarkContextMenu & DarkSectionPanel

This commit is contained in:
Robin 2015-09-18 12:08:22 +01:00
parent a0d9e343e9
commit 13c57d8162
5 changed files with 229 additions and 3 deletions

View File

@ -0,0 +1,16 @@
using System.Windows.Forms;
namespace DarkUI
{
public class DarkContextMenu : ContextMenuStrip
{
#region Constructor Region
public DarkContextMenu()
{
Renderer = new DarkMenuRenderer();
}
#endregion
}
}

View File

@ -0,0 +1,145 @@
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace DarkUI
{
public class DarkSectionPanel : Panel
{
#region Field Region
private string _sectionHeader;
#endregion
#region Property Region
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new Padding Padding
{
get { return base.Padding; }
}
[Category("Appearance")]
[Description("The section header text associated with this control.")]
public string SectionHeader
{
get { return _sectionHeader; }
set
{
_sectionHeader = value;
Invalidate();
}
}
#endregion
#region Constructor Region
public DarkSectionPanel()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
base.Padding = new Padding(1, 25, 1, 1);
}
#endregion
#region Event Handler Region
protected override void OnEnter(System.EventArgs e)
{
base.OnEnter(e);
Invalidate();
}
protected override void OnLeave(System.EventArgs e)
{
base.OnLeave(e);
Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (Controls.Count > 0)
Controls[0].Focus();
}
#endregion
#region Paint Region
protected override void OnPaint(PaintEventArgs e)
{
var g = e.Graphics;
var rect = ClientRectangle;
// Fill body
using (var b = new SolidBrush(Colors.GreyBackground))
{
g.FillRectangle(b, rect);
}
// Draw header
var bgColor = ContainsFocus ? Colors.BlueBackground : Colors.HeaderBackground;
var darkColor = ContainsFocus ? Colors.DarkBlueBorder : Colors.DarkBorder;
var lightColor = ContainsFocus ? Colors.LightBlueBorder : Colors.LightBorder;
using (var b = new SolidBrush(bgColor))
{
var bgRect = new Rectangle(0, 0, rect.Width, 25);
g.FillRectangle(b, bgRect);
}
using (var p = new Pen(darkColor))
{
g.DrawLine(p, rect.Left, 0, rect.Right, 0);
g.DrawLine(p, rect.Left, 25 - 1, rect.Right, 25 - 1);
}
using (var p = new Pen(lightColor))
{
g.DrawLine(p, rect.Left, 1, rect.Right, 1);
}
var xOffset = 3;
using (var b = new SolidBrush(Colors.LightText))
{
var textRect = new Rectangle(xOffset, 0, rect.Width - 4 - xOffset, 25);
var format = new StringFormat
{
Alignment = StringAlignment.Near,
LineAlignment = StringAlignment.Center,
FormatFlags = StringFormatFlags.NoWrap,
Trimming = StringTrimming.EllipsisCharacter
};
g.DrawString(SectionHeader, Font, b, textRect, format);
}
// Draw border
using (var p = new Pen(Colors.DarkBorder, 1))
{
var modRect = new Rectangle(rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);
g.DrawRectangle(p, modRect);
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// Absorb event
}
#endregion
}
}

View File

@ -44,6 +44,9 @@
<Compile Include="Controls\DarkButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\DarkContextMenu.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\DarkLabel.cs">
<SubType>Component</SubType>
</Compile>
@ -53,6 +56,9 @@
<Compile Include="Controls\DarkScrollBar.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\DarkSectionPanel.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\DarkSeparator.cs">
<SubType>Component</SubType>
</Compile>

View File

@ -78,10 +78,17 @@
this.toolStripStatusLabel6 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel5 = new System.Windows.Forms.ToolStripStatusLabel();
this.btnDialog = new DarkUI.DarkButton();
this.darkSectionPanel1 = new DarkUI.DarkSectionPanel();
this.btnMessageBox = new DarkUI.DarkButton();
this.darkContextMenu1 = new DarkUI.DarkContextMenu();
this.testToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.moreTestToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.test3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMain.SuspendLayout();
this.toolMain.SuspendLayout();
this.darkStatusStrip1.SuspendLayout();
this.darkSectionPanel1.SuspendLayout();
this.darkContextMenu1.SuspendLayout();
this.SuspendLayout();
//
// mnuMain
@ -549,21 +556,63 @@
this.btnDialog.TabIndex = 3;
this.btnDialog.Text = "Dialog";
//
// darkSectionPanel1
//
this.darkSectionPanel1.Controls.Add(this.btnMessageBox);
this.darkSectionPanel1.Location = new System.Drawing.Point(431, 157);
this.darkSectionPanel1.Name = "darkSectionPanel1";
this.darkSectionPanel1.SectionHeader = "Section test";
this.darkSectionPanel1.Size = new System.Drawing.Size(221, 224);
this.darkSectionPanel1.TabIndex = 5;
//
// btnMessageBox
//
this.btnMessageBox.Location = new System.Drawing.Point(128, 73);
this.btnMessageBox.ContextMenuStrip = this.darkContextMenu1;
this.btnMessageBox.Location = new System.Drawing.Point(10, 35);
this.btnMessageBox.Name = "btnMessageBox";
this.btnMessageBox.Padding = new System.Windows.Forms.Padding(5);
this.btnMessageBox.Size = new System.Drawing.Size(97, 30);
this.btnMessageBox.TabIndex = 4;
this.btnMessageBox.TabIndex = 5;
this.btnMessageBox.Text = "Message Box";
//
// darkContextMenu1
//
this.darkContextMenu1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(63)))), ((int)(((byte)(65)))));
this.darkContextMenu1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.darkContextMenu1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.testToolStripMenuItem,
this.moreTestToolStripMenuItem,
this.test3ToolStripMenuItem});
this.darkContextMenu1.Name = "darkContextMenu1";
this.darkContextMenu1.Size = new System.Drawing.Size(125, 70);
//
// testToolStripMenuItem
//
this.testToolStripMenuItem.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.testToolStripMenuItem.Name = "testToolStripMenuItem";
this.testToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.testToolStripMenuItem.Text = "Test";
//
// moreTestToolStripMenuItem
//
this.moreTestToolStripMenuItem.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.moreTestToolStripMenuItem.Name = "moreTestToolStripMenuItem";
this.moreTestToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.moreTestToolStripMenuItem.Text = "More test";
//
// test3ToolStripMenuItem
//
this.test3ToolStripMenuItem.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.test3ToolStripMenuItem.Name = "test3ToolStripMenuItem";
this.test3ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.test3ToolStripMenuItem.Text = "Test 3";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(784, 562);
this.Controls.Add(this.btnMessageBox);
this.Controls.Add(this.darkSectionPanel1);
this.Controls.Add(this.btnDialog);
this.Controls.Add(this.darkStatusStrip1);
this.Controls.Add(this.toolMain);
@ -580,6 +629,8 @@
this.toolMain.PerformLayout();
this.darkStatusStrip1.ResumeLayout(false);
this.darkStatusStrip1.PerformLayout();
this.darkSectionPanel1.ResumeLayout(false);
this.darkContextMenu1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -636,7 +687,12 @@
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel6;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel5;
private DarkUI.DarkButton btnDialog;
private DarkUI.DarkSectionPanel darkSectionPanel1;
private DarkUI.DarkButton btnMessageBox;
private DarkUI.DarkContextMenu darkContextMenu1;
private System.Windows.Forms.ToolStripMenuItem testToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem moreTestToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem test3ToolStripMenuItem;
}
}

View File

@ -357,4 +357,7 @@
<metadata name="darkStatusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>257, 17</value>
</metadata>
<metadata name="darkContextMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>398, 17</value>
</metadata>
</root>