111,126
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Windows.Forms;
class Form1 : Form
{
TextBox tbx1, tbx2, tbx3;
Form1()
{
Label lbl1 = new Label();
lbl1.Parent = this;
lbl1.Text = "数量(&N)";
lbl1.Top = 5;
lbl1.AutoSize = true;
tbx1 = new TextBox();
tbx1.Parent = this;
tbx1.Left = 50;
tbx1.TextChanged += new EventHandler(Changed);
Label lbl2 = new Label();
lbl2.Parent = this;
lbl2.Text = "单价(&P)";
lbl2.Top = 35;
lbl2.AutoSize = true;
tbx2 = new TextBox();
tbx2.Parent = this;
tbx2.Left = 50;
tbx2.Top = 30;
tbx2.TextChanged += new EventHandler(Changed);
Label lbl3 = new Label();
lbl3.Parent = this;
lbl3.Text = "金额(&M)";
lbl3.Top = 65;
lbl3.AutoSize = true;
tbx3 = new TextBox();
tbx3.Parent = this;
tbx3.Left = 50;
tbx3.Top = 60;
}
void Changed(Object sender, EventArgs e)
{
double d1, d2;
double.TryParse(tbx1.Text, out d1);
double.TryParse(tbx2.Text, out d2);
tbx3.Text = (d1 * d2).ToString();
}
static void Main()
{
Application.Run(new Form1());
}
} using System;
using System.Windows.Forms;
class Form1 : Form
{
TextBox tbx1, tbx2, tbx3;
Form1()
{
Label lbl1 = new Label();
lbl1.Parent = this;
lbl1.Text = "数量(&N)";
lbl1.Top = 5;
lbl1.AutoSize = true;
tbx1 = new TextBox();
tbx1.Parent = this;
tbx1.Left = 50;
tbx1.KeyUp += new KeyEventHandler(TextBoxKeyUp);
Label lbl2 = new Label();
lbl2.Parent = this;
lbl2.Text = "单价(&P)";
lbl2.Top = 35;
lbl2.AutoSize = true;
tbx2 = new TextBox();
tbx2.Parent = this;
tbx2.Left = 50;
tbx2.Top = 30;
tbx2.KeyUp += new KeyEventHandler(TextBoxKeyUp);
Label lbl3 = new Label();
lbl3.Parent = this;
lbl3.Text = "金额(&M)";
lbl3.Top = 65;
lbl3.AutoSize = true;
tbx3 = new TextBox();
tbx3.Parent = this;
tbx3.Left = 50;
tbx3.Top = 60;
}
void TextBoxKeyUp(Object sender, KeyEventArgs e)
{
double d1, d2;
double.TryParse(tbx1.Text, out d1);
double.TryParse(tbx2.Text, out d2);
tbx3.Text = (d1 * d2).ToString();
}
static void Main()
{
Application.Run(new Form1());
}
}