《Windows可视化编程》复习资料-温延龙V3 下载本文

内容发布更新时间 : 2024/5/28 14:46:05星期一 下面是文章的全部内容请认真阅读。

begin++; } }

for(i = 0;i < 10;i++) printf(\printf(\}

8.编写一个Windows应用程序,输入梯形的上底、下底和高,单击“面积”按钮后输出梯形的面积。

窗体上拉三个文本框(注意添加顺序,必须从左往右放三个,分别用来输入上底,下底,高),一个按钮(button),一个标签(label),然后双击按钮,贴这段代码: void Button1Click(object sender, EventArgs e) {

// 键入以下代码。 try { // 上底

int topline = System.Convert.ToInt32(textBox1.Text); // 下底

int baseline = System.Convert.ToInt32(textBox2.Text); // 高

int height = System.Convert.ToInt32(textBox3.Text); if (topline>0 && baseline>0 && height>0) {

label1.Text = ((topline+ baseline) * height *1.0 /2).ToString(); } else {

label1.Text = \上底,下底,高必须都大于零。\} }

catch(Exception) {

label1.Text = \您输入有误,必须输入数字。\

}

//代码结束。 }

9.编写一个Windows应用程序,实现摄氏温度和华氏温度的转换。摄氏温度C和华氏温度F之间的转换公式为:F=9/5C+32 C=5/9(F-32)。 使用VS的Windows 应用程序代码如下: using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;

using System.Windows.Forms; namespace WindowsApplication1 {

public partial class MainForm :Form {

//f=9/5*c+32,其中f为华氏温度,c为摄氏温度 double f,c = 0.00; public MainForm() {

InitializeComponent(); }

private void Form1_Load(object sender,EventArgs e) { }

private void btnH_Click(object sender,EventArgs e) {

if (this.txtOld.Text == \{

this.txtOld.Focus();

MessageBox.Show(\请输入温度!\

} else { try {

if (((Button)sender).Name == \{

f = double.Parse(this.txtOld.Text); this.txtNew.Text = \}

if (((Button)sender).Name == \{

c = double.Parse(this.txtOld.Text); this.txtNew.Text = \} }

catch (Exception) {

MessageBox.Show(\请输入正确信息!\this.txtOld.Text = \this.txtOld.Focus(); } } } } }

10.为按钮编写“单击”(Click)事件处理代码,实现在TextBox中显示所填与所选信息。

private void button1_Click(object sender, EventArgs e) {

string a=\ string b=\

if (radioButton1.Checked)

{

a = \男\ } else { a = \女\ }

if (checkBox1.Checked) { b = b + checkBox1.Text; }

if (checkBox2.Checked) {

b = b + checkBox2.Text; }

if (checkBox3.Checked) {

b = b + checkBox3.Text; }

if (checkBox4.Checked) {

b = b + checkBox4.Text; }

textBox3.Text = \姓名\班级\性别\爱好\ }

11.编写一个Windows应用程序,单击选定的CheckBox或RadioButton后,填出消息框,显示被选中信息。

12.将窗体上的文本框中的字体,改变为所需的大小、颜色和字体。