C# User Controls Text Display, Settings Component
How to draw a convenient text display component, text set value components (TextShow, TextSet)?
The purpose of drawing this control is to facilitate one-click to deal with the label display (you can customize the method to display the text color, etc.), easy to customize the method and omit the process of dragging and dropping them one by one.
Pure Definition Properties
[Text Settings]: Font, Label, Value, Unit; Event Method: Enter, Leave, KeyDown
[Text Display]: Variable Name, Variable Value, Unit, Font, Control Scale
Straight to the code.
[Text Setting]
public partial class TextSet : UserControl
{
public TextSet()
{
InitializeComponent();
this.txt_Value.ReadOnly = true;
}
#region causality calligraphic style、tab (of a window) (computing)、(be) worth、unit (of measure)
private Font textFont = new Font("Microsoft Black and White (computer science)", 12);
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("calligraphic style格式")]
public Font TextFont
{
get { return textFont; }
set
{
if (value != null)
{
textFont = value;
this.lbl_Title.Font = this.lbl_Unit.Font = this.txt_Value.Font = textFont;
}
}
}
private Color textColor = ;
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("Text color")]
public Color TextColor
{
get { return textColor; }
set
{
textColor = value;
this.lbl_Title.ForeColor = this.lbl_Unit.ForeColor = this.txt_Value.ForeColor = textColor;
}
}
private float textScale = 0.37f;
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("Control Scale")]
public float TextScale
{
get { return textScale; }
set
{
textScale = value;
this.[0].Width = ( - textScale * ) * 0.75f;
this.[1].Width = textScale * ;
this.[2].Width = ( - textScale * ) * 0.25f;
}
}
private string varTitle = "variable name";
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("variable name")]
public string VarTitle
{
get { return varTitle; }
set
{
varTitle = value;
this.lbl_Title.Text = varTitle;
}
}
private string varValue = "21.50";
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("输入(be) worth")]
public string VarValue
{
get { return varValue; }
set
{
varValue = value;
this.txt_Value.Text = varValue;
}
}
private string varUnit = "℃";
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("unit (of measure)")]
public string VarUnit
{
get { return varUnit; }
set
{
varUnit = value;
this.lbl_Unit.Text = varUnit;
}
}
#endregion
#region input enable event
//Input Flag Bit
public bool IsSetting { get; set; }
private void txt_Value_Enter(object sender, EventArgs e)
{
IsSetting = true;
this.txt_Value.ReadOnly = false;
}
private void txt_Value_Leave(object sender, EventArgs e)
{
IsSetting = false;
this.txt_Value.ReadOnly = true;
}
//Add Input Completion Event
public event EventHandler SettingChanged;
private void txt_Value_KeyDown(object sender, KeyEventArgs e)
{
if ( == )
{
//finesse:Input completion to move focus~Input box is grayed out
this.lbl_Title.Focus();
//activate a trigger event
SettingChanged?.Invoke(this, e);
}
}
#endregion
}
[Text Display]
public partial class TextShow : UserControl
{
public TextShow()
{
InitializeComponent();
}
#region Fields variable name、variable value、unit (of measure)、calligraphic style、control scale
//[Browsable(true)]
//[Category("opening (chess jargon)_G")]
//[Description("variable name")]
//public String VarName { get; set; }
private Font textFont = new Font("Segoe UI Variable Display", 15, );
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("calligraphic style格式")]
public Font TextFont
{
get { return textFont; }
set
{
if (value != null)
{
textFont = value;
this.lbl_Value.Font = this.lbl_Unit.Font = textFont;
}
}
}
private Color textColor = ;
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("Text color")]
public Color TextColor
{
get { return textColor; }
set
{
textColor = value;
this.lbl_Value.ForeColor = this.lbl_Unit.ForeColor = textColor;
}
}
private string varVlaue = "1.0E-5";
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("variable value")]
public string VarVlaue
{
get { return varVlaue; }
set
{
varVlaue = value;
this.lbl_Value.Text = varVlaue;
}
}
private string unit = "Pa";
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("unit (of measure)")]
public string Unit
{
get { return unit; }
set
{
unit = value;
this.lbl_Unit.Text = unit;
}
}
private float textScale = 0.6f;
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("control scale")]
public float TextScale
{
get { return textScale; }
set
{
textScale = value;
this.[0].Width = textScale * ;
this.[1].Width = - textScale * ;
}
}
#endregion
Custom drawing components to make it easier to use them directly later is a one-off thing.
End