Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetroLineDivider.cs #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
156 changes: 156 additions & 0 deletions MetroFramework/Controls/MetroLineDivider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using MetroFramework.Components;
using MetroFramework.Drawing;
using MetroFramework.Interfaces;

namespace MetroFramework.Controls
{
public enum LineDividerPositions : int
{
/// <summary>
/// Poistion the Divider to the Right of the Text
/// </summary>
Right,
/// <summary>
/// Position the Divider the the Left of the Text
/// </summary>
Below
}

public partial class MetroLineDivider : MetroLabel
{

/// <summary>
/// Divider Position
/// </summary>
private LineDividerPositions m_DividerPosition = LineDividerPositions.Right;

public MetroLineDivider()
{
InitializeComponent();
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
SizeF sf = GetPreferredSize(Size.Empty);
SolidBrush m_oLineDividerColor = new SolidBrush(this.DefaultForecolor());

if (this.DividerPosition == LineDividerPositions.Right)
{
Rectangle rect = new Rectangle(Convert.ToInt32(sf.Width), Convert.ToInt32((Convert.ToInt32(sf.Height) / 2) + 1), this.Width - Convert.ToInt32(sf.Width), 1);
e.Graphics.FillRectangle(m_oLineDividerColor, rect);
}
else if (this.DividerPosition == LineDividerPositions.Below)
{
Rectangle rect = new Rectangle(1, Convert.ToInt32(sf.Height), this.Width, 1);
e.Graphics.FillRectangle(m_oLineDividerColor, rect);
}

}

/// <summary>
/// Returns the label's default color
/// </summary>
/// <returns></returns>
private Color DefaultForecolor()
{
if (UseCustomForeColor)
{
return ForeColor;
}
else
{
if (!Enabled)
{
if (Parent != null)
{
if (Parent is MetroTile)
{
return MetroPaint.ForeColor.Tile.Disabled(Theme);
}
else
{
return MetroPaint.ForeColor.Label.Normal(Theme);
}
}
else
{
return MetroPaint.ForeColor.Label.Disabled(Theme);
}
}
else
{
if (Parent != null)
{
if (Parent is MetroTile)
{
return MetroPaint.ForeColor.Tile.Normal(Theme);
}
else
{
if (this.UseStyleColors)
{
return MetroPaint.GetStyleColor(Style);
}
else
{
return MetroPaint.ForeColor.Label.Normal(Theme);
}
}
}
else
{
if (UseStyleColors)
{
return MetroPaint.GetStyleColor(Style);
}
else
{
return MetroPaint.ForeColor.Label.Normal(Theme);
}
}
}
}
}


/// <summary>
/// Sets/Gets the position of the line divider
/// </summary>
[Description("The location of the line divider"),
Category("Appearance"), DefaultValue(LineDividerPositions.Right)]
public LineDividerPositions DividerPosition
{
get { return this.m_DividerPosition; }
set
{
this.m_DividerPosition = value;
this.Invalidate();
}
}

/// <summary>
/// Set the Auto Size to False by default and make it not browsable
/// </summary>
[Browsable(false)]
public override bool AutoSize
{
get
{
return base.AutoSize;
}
set
{
base.AutoSize = false;
}
}
}
}