您的位置:首页 > 编程语言 > C#

C#第七次上机

2016-05-01 15:44 351 查看
1. 题目要求:

窗体启动后自动位于屏幕中央;窗体大小不可调;窗体背景色为白色;窗体标题为“我的窗体实验”;窗体上有两个标签,其中一个为链接标签,链接标签字体为宋体16号;单击该链接可以打开烟大主页;单击“结束”按钮,程序即可结束。

输入代码:

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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)
{

}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.ytu.edu.cn/");
}

private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}


运行截图:



2.题目要求:

窗体标题为“我的文本框实验”;窗体上有一个标签,内容如图;窗体上有一个文本框,文本框只能输入0-9十种数字,最多输入8个字符。单击“结束”按钮程序即可结束。

输入代码:

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{

}

private void label1_Click_1(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void label1_Click_2(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
this.Close();
}

private void textBox1_TextChanged_1(object sender, EventArgs e)
{

}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar<'0'||e.KeyChar>'9')
{
e.Handled = true;
}
else
{
Console.WriteLine("请输入数字: ");
}
}

private void label2_Click(object sender, EventArgs e)
{

}
}

}


运行截图:



总结:

C#的window应用设计感觉和Android的UI有许多共同之处,但比Android更容易入门,这可能是为什么大学课程把Android放在后面的原因吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: