![](/img/trans.png)
[英]In C#, how can I change a solidbrush color dynamically using numericupdown control?
[英]how to change label size dynamically using numericupdown in C#
我想知道如何使用C#在数字上下列表中使用当前值更改标签大小
Label sample;
public Form1()
{
InitializeComponent();
sample = new Label();
sample.Location = new Point(numericUpDown1.Left, numericUpDown1.Bottom);
sample.Size = numericUpDown1.Size;
sample.BackColor = Color.Blue;
Controls.Add(sample);
numericUpDown1.Value = sample.Width;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
sample.Width = (int)numericUpDown1.Value;
}
如果您指的是字体大小,那么这是另一个示例:
Label sample;
Font sampleFont;
public Form1()
{
InitializeComponent();
sample = new Label();
sample.Text = "Sample Text";
sample.AutoSize = true;
sample.Location = new Point(numericUpDown1.Left, numericUpDown1.Bottom);
sample.Size = numericUpDown1.Size;
sampleFont = (Font)Font.Clone();
sample.Font = sampleFont;
Controls.Add(sample);
numericUpDown1.Value = (decimal)sampleFont.Size;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
Font newFont = new Font(sampleFont.FontFamily, (float)numericUpDown1.Value);
sample.Font = newFont;
sampleFont.Dispose();
sampleFont = newFont;
}
默认情况下,标签的AutoSize
属性设置为true
。 如果将其显式更改为false
,则可以控制大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.