NumericUpDown的增减值



我有以下问题。我创建了一个有两个NumericUpDown的表单,我想从它们中增加/减少0.01的值。我尝试使用numericupdownoobject . increment =0.01M,但之后没有变化,值不改变。这是代码:

namespace Proiect1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 1;
int o = 1;
private void button1_Click(object sender, EventArgs e)
{
Label l = new Label();
Label l2 = new Label();
NumericUpDown t = new NumericUpDown();
NumericUpDown t2 = new NumericUpDown();
l.Top = i * 25;
l.Left = 3;
l2.Top = i * 25;
l2.Left = 63;
t.Value = 0;
t.Increment = 0.01M;
t.Top = i * 25;
t.Left = 30;
t2.Value = 0;
t2.Top = i * 25;
t2.Left = 90;
i++;
t.Size =new System.Drawing.Size(30, 30);
t2.Size = new System.Drawing.Size(30, 30);
l.Size = new System.Drawing.Size(25, 20);
l2.Size = new System.Drawing.Size(29, 20);
l.Text = "n" + o;
l2.Text = "w" + o;
o++;
panel1.Controls.Add(t);
panel1.Controls.Add(t2);
panel1.Controls.Add(l);
panel1.Controls.Add(l2);
panel1.AutoScroll = true;


}

试试这个

这将在创建时设置整个表单,但只在单击时增加。

看起来你的解决方案每次点击都在重新创造一切。

p。我做Winforms/WPF已经有一段时间了

namespace Proiect1
{
public partial class Form1 : Form
{
NumericUpDown _t = new NumericUpDown();
NumericUpDown _t2 = new NumericUpDown();
Label _l = new Label();
Label _l2 = new Label();

public Form1()
{
InitializeComponent();
int i = 1;
int o = 1;

_l.Top = i * 25;
_l.Left = 3;
_l2.Top = i * 25;
_l2.Left = 63;
_t.Value = 0;
_t.Increment = 0.01;
_t.Top = i * 25;
_t.Left = 30;
_t2.Value = 0;
_t2.Top = i * 25;
_t2.Left = 90;
i++;
_t.Size =new System.Drawing.Size(30, 30);
_t2.Size = new System.Drawing.Size(30, 30);
_l.Size = new System.Drawing.Size(25, 20);
_l2.Size = new System.Drawing.Size(29, 20);
_l.Text = "n" + o;
_l2.Text = "w" + o;
o++;
panel1.Controls.Add(_t);
panel1.Controls.Add(_t2);
panel1.Controls.Add(l_);
panel1.Controls.Add(l_2);
panel1.AutoScroll = true;
}

private void button1_Click(object sender, EventArgs e)
{
_t.Increment = 0.01;
}