1、 if (checkBox1.Checked) ah += checkBox1.Text; if (checkBox2.Checked) ah += + checkBox2.Text; if (checkBox3.Checked) ah += + checkBox3.Text; str = 你的姓名是: + name + rn + 你的性别是: + sex + 你的爱好是: + ah;2ListBox private void button2_Click(object sender, EventArgs e) bool canAdd = true; string minfo= if (text
2、Box1.Text = ) canAdd = false; minfo = 添加项不能为空! int z= listBox1.FindStringExact(textBox1.Text); if (z != -1) canAdd = false;列表中已经存在“ + textBox1.Text + ”,无法完成添加操作! if (canAdd)/没有相同项时,执行下面的操作 listBox1.Items.Add(textBox1.Text); else/否则提示信息 DialogResult dlogRs= MessageBox.Show(minfo, 系统提示, MessageBoxButt
3、ons.OK, MessageBoxIcon.Information); if (dlogRs = DialogResult.OK) textBox1.Focus(); textBox1.Select(0, textBox1.Text.Length); private void button1_Click(object sender, EventArgs e) if (listBox2.Items.Count -1) listBox2.Items.Clear(); button1.Enabled = false; private void listBox1_DoubleClick(object
4、 sender, EventArgs e) if (listBox1.SelectedIndex != -1) listBox2.Items.Add(listBox1.SelectedItem); listBox1.Items.Remove(listBox1.SelectedItem); if (button1.Enabled = false) button1.Enabled = true;3.Math类if (comboBox2.SelectedIndex!=-1|comboBox2.Text!=double ch = double.Parse(comboBox2.Text);double
5、result=0;switch (comboBox1.SelectedIndex)case 0: result = Math.Sin(ch * Math.PI / 180); break;/x* Math.PI / 180 转换成角度case 1: result = Math.Cos(ch * Math.PI / 180);case 2: result = Math.Sqrt(ch);label3.Text = 结果= + result.ToString(0.00);elsestring minfo = 请选择或输入一个值!MessageBox.Show(minfo, private void
6、 Form1_Load(object sender, EventArgs e)comboBox1.SelectedIndex = 0;4.PictureBox、RadioButton、ScrollBar private void Form1_Load(object sender, EventArgs e) radioButton1.Checked=true; pictureBox1.Load(图片1.jpg/注意:在调试时需要将图片复制到Debug目录下 pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Wi
7、dth = 200; hScrollBar1.Minimum = 200; hScrollBar1.Maximum = 300; hScrollBar1.Value = 200; hScrollBar1.SmallChange = 2; hScrollBar1.LargeChange = 5; private void radioButton2_CheckedChanged(object sender, EventArgs e) if (radioButton1.Checked) pictureBox1.Load( else pictureBox1.Load(图片2.jpg private v
8、oid radioButton1_CheckedChanged(object sender, EventArgs e) /注意 此处也可radioButton2 共用一段代码,这里进行了改写 if (radioButton2.Checked) pictureBox1.Load( else pictureBox1.Load( private void hScrollBar1_Scroll(object sender, ScrollEventArgs e) pictureBox1.Width = hScrollBar1.Value;5.RichTextBox、FontDialog、ColorDia
9、log 、Menu private void 退出UToolStripMenuItem_Click(object sender, EventArgs e) this.Close(); private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) open = C:Documents and SettingsAdministratorMy Documents/设定默认目录 open = /默认文件名纯文本(*.txt)|*.txt|RTF文件(*.rtf)|*.rtf/文件过滤 open = 2;/设定默认过滤器 if (o
10、pen() = DialogResult.OK) toolStripStatusLabel1.Text = open; if (open = 1) richTextBox1.Load, RichTextBoxStreamType.PlainText); richTextBox1.Load); private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) string fname = open(); save = true; if (fname != & fname !open) save = fname; save = 新
11、建文件) save = open; if (save() = DialogResult.OK) if (save = 1) richTextBox1.Save, RichTextBoxStreamType.PlainText); richTextBox1.Save); /将是否修改值 重置 richTextBox1.Modified = false; toolStripComboBox1.SelectedIndex = 0;/字号列表初始化 选择第一项 toolStripStatusLabel2.Text = DateTime.Now.ToLocalTime().ToString();/201
12、1-11-19 16:08:07 toolStripStatusLabel1.Text =暂未打开任何文件! private void 字体ToolStripMenuItem_Click(object sender, EventArgs e) FontDialog fdg = new FontDialog(); fdg.ShowDialog(); richTextBox1.SelectionFont = fdg.Font; private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e) ColorDialog cdg = new ColorDialog(); cdg.ShowDialog(); richTextBox1.SelectionColor = cdg.Color; private void timer1_Tick(object sender, EventArgs e) toolStripStatus
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1