题目要求:
设计如图所示的窗体。
要求:窗体启动后自动位于屏幕中央;窗体大小不可调;窗体背景色为白色;窗体标题为“我的窗体实验”;窗体上有两个标签,其中一个为链接标签,链接标签字体为宋体16号;单击该链接可以打开烟大主页;单击“结束”按钮程序即可结束。
参考代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "我的窗体实验";
this.CenterToScreen();
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.BackColor = Color.White;
this.label1.Text = "下面是一个链接标签,单击该标签即可链接到烟台大学主页";
this.linkLabel1.Text = "烟台大学";
this.button1.Text = "结束";
}
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();
}
}
}
自动生成的Designer文件:
namespace WindowsFormsApplication5_3
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(351, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(134, 55);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(84, 59);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 18);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// linkLabel1
//
this.linkLabel1.AutoSize = true;
this.linkLabel1.Font = new System.Drawing.Font("SimSun", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.linkLabel1.Location = new System.Drawing.Point(107, 141);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(175, 33);
this.linkLabel1.TabIndex = 2;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "linkLabel1";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(613, 244);
this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.LinkLabel linkLabel1;
}
}