SeparatorLabel-Steuerelement
Dieses Steuerelement kombiniert ein Label mit einer horizontalen Linie, um es als Trennzeile und Überschrift zwischen verschiedenen Gruppen von Steuerelementen zu verwenden.
Kompatibilität: 2.0, 3.5
Download (CS-Datei, 3 kB, Stand: 18. September 2009)
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Unclassified.UI
{
public class SeparatorLabel : UserControl
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Label label1;
[Browsable(false)]
public new bool TabStop
{
get { return false; }
set { base.TabStop = false; }
}
public SeparatorLabel()
{
InitializeComponent();
AutoScaleMode = AutoScaleMode.None;
TabStop = false;
DoLayout();
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Margin = new System.Windows.Forms.Padding(0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label1.SizeChanged += new System.EventHandler(this.label1_SizeChanged);
//
// SeparatorLabel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Name = "SeparatorLabel";
this.Size = new System.Drawing.Size(150, 78);
this.ResumeLayout(false);
this.PerformLayout();
}
[Browsable(true)]
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text
{
get
{
return label1.Text;
}
set
{
label1.Text = value;
}
}
private void label1_SizeChanged(object sender, EventArgs e)
{
DoLayout();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Paint separator line
Pen p = new Pen(SystemColors.ControlDark);
e.Graphics.DrawLine(p, label1.Width + 2, Height / 2 + 1, Width, Height / 2 + 1);
p.Dispose();
p = new Pen(SystemColors.ControlLightLight);
e.Graphics.DrawLine(p, label1.Width + 2, Height / 2 + 2, Width, Height / 2 + 2);
p.Dispose();
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
DoLayout();
}
protected override void OnFontChanged(EventArgs e)
{
base.OnFontChanged(e);
DoLayout();
}
private void DoLayout()
{
Height = label1.Height;
}
}
}
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Unclassified.UI
{
public class SeparatorLabel : UserControl
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Label label1;
[Browsable(false)]
public new bool TabStop
{
get { return false; }
set { base.TabStop = false; }
}
public SeparatorLabel()
{
InitializeComponent();
AutoScaleMode = AutoScaleMode.None;
TabStop = false;
DoLayout();
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Margin = new System.Windows.Forms.Padding(0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label1.SizeChanged += new System.EventHandler(this.label1_SizeChanged);
//
// SeparatorLabel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Name = "SeparatorLabel";
this.Size = new System.Drawing.Size(150, 78);
this.ResumeLayout(false);
this.PerformLayout();
}
[Browsable(true)]
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text
{
get
{
return label1.Text;
}
set
{
label1.Text = value;
}
}
private void label1_SizeChanged(object sender, EventArgs e)
{
DoLayout();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Paint separator line
Pen p = new Pen(SystemColors.ControlDark);
e.Graphics.DrawLine(p, label1.Width + 2, Height / 2 + 1, Width, Height / 2 + 1);
p.Dispose();
p = new Pen(SystemColors.ControlLightLight);
e.Graphics.DrawLine(p, label1.Width + 2, Height / 2 + 2, Width, Height / 2 + 2);
p.Dispose();
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
DoLayout();
}
protected override void OnFontChanged(EventArgs e)
{
base.OnFontChanged(e);
DoLayout();
}
private void DoLayout()
{
Height = label1.Height;
}
}
}
Bilder
| Beispiel im Visual Studio 2005 Designer |
Änderungen
18. September 2009
Erste Version
Licence, terms of use
This programme is freely available as source code and compiled version, without restrictions (“public domain”). There is no warranty, not even for merchantability or fitness for a particular purpose. I am not liable for any damage caused through appropriate or inappropriate use.


Statistik wird geladen...