第一节课作业
设计一个Form
1. 窗体:三个button,一个textBox
2. 属性设置
编写代码
双击每个控件,就可以进行代码编辑
1. 显示
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "Hello World";//在文本框中显示“hello world”
}
2. 清除
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";//将文本框显示的内容清空
}
3. 弹出一个新的对话框
private void button3_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World");//弹出一个对话框,显示“Hello world"
}
(一) 实现以下效果
第二节课作业
实训指导:乘法计算器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
}
private void maskedTextBox4_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
float num1 = 0;
float num2 = 0;
float result=0;
num1=float.Parse(textBox1.Text);//将文本框输入的字符转化为数值
num2=float.Parse(textBox2.Text);
result = num1 * num2;
textBox3.Text = result.ToString();//将数值转换成字符
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
}