⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;    //引用命名空间

namespace 例链接标签
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.LinkLabel lnk163;
		private System.Windows.Forms.LinkLabel lnksina;
		private System.Windows.Forms.LinkLabel lnkbaidu;
		private System.Windows.Forms.LinkLabel lnkgoogle;
		private System.Windows.Forms.LinkLabel lnkLocal;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
            this.lnksina = new System.Windows.Forms.LinkLabel();
            this.lnkbaidu = new System.Windows.Forms.LinkLabel();
            this.lnk163 = new System.Windows.Forms.LinkLabel();
            this.lnkgoogle = new System.Windows.Forms.LinkLabel();
            this.lnkLocal = new System.Windows.Forms.LinkLabel();
            this.SuspendLayout();
            // 
            // lnksina
            // 
            this.lnksina.AutoSize = true;
            this.lnksina.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lnksina.LinkArea = new System.Windows.Forms.LinkArea(3, 15);
            this.lnksina.Location = new System.Drawing.Point(37, 62);
            this.lnksina.Name = "lnksina";
            this.lnksina.Size = new System.Drawing.Size(183, 22);
            this.lnksina.TabIndex = 1;
            this.lnksina.TabStop = true;
            this.lnksina.Tag = "\"www.sina.com.cn\"";
            this.lnksina.Text = "新浪(www.sina.com.cn)";
            this.lnksina.UseCompatibleTextRendering = true;
            this.lnksina.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkOpen_LinkClicked);
            // 
            // lnkbaidu
            // 
            this.lnkbaidu.AutoSize = true;
            this.lnkbaidu.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lnkbaidu.LinkArea = new System.Windows.Forms.LinkArea(3, 13);
            this.lnkbaidu.Location = new System.Drawing.Point(37, 93);
            this.lnkbaidu.Name = "lnkbaidu";
            this.lnkbaidu.Size = new System.Drawing.Size(168, 22);
            this.lnkbaidu.TabIndex = 2;
            this.lnkbaidu.TabStop = true;
            this.lnkbaidu.Tag = "\"www.baidu.com\"";
            this.lnkbaidu.Text = "百度(www.baidu.com)";
            this.lnkbaidu.UseCompatibleTextRendering = true;
            this.lnkbaidu.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linClear_LinkClicked);
            // 
            // lnk163
            // 
            this.lnk163.AutoSize = true;
            this.lnk163.LinkArea = new System.Windows.Forms.LinkArea(3, 11);
            this.lnk163.Location = new System.Drawing.Point(37, 31);
            this.lnk163.Name = "lnk163";
            this.lnk163.Size = new System.Drawing.Size(152, 22);
            this.lnk163.TabIndex = 4;
            this.lnk163.TabStop = true;
            this.lnk163.Text = "网易(www.163.com)";
            this.lnk163.UseCompatibleTextRendering = true;
            this.lnk163.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnk163_LinkClicked);
            // 
            // lnkgoogle
            // 
            this.lnkgoogle.AutoSize = true;
            this.lnkgoogle.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lnkgoogle.LinkArea = new System.Windows.Forms.LinkArea(7, 14);
            this.lnkgoogle.Location = new System.Drawing.Point(37, 123);
            this.lnkgoogle.Name = "lnkgoogle";
            this.lnkgoogle.Size = new System.Drawing.Size(191, 22);
            this.lnkgoogle.TabIndex = 5;
            this.lnkgoogle.TabStop = true;
            this.lnkgoogle.Tag = "\"www.google.com\"";
            this.lnkgoogle.Text = "Google(www.google.com)";
            this.lnkgoogle.UseCompatibleTextRendering = true;
            this.lnkgoogle.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkgoogle_LinkClicked);
            // 
            // lnkLocal
            // 
            this.lnkLocal.AutoSize = true;
            this.lnkLocal.LinkArea = new System.Windows.Forms.LinkArea(5, 9);
            this.lnkLocal.Location = new System.Drawing.Point(37, 154);
            this.lnkLocal.Name = "lnkLocal";
            this.lnkLocal.Size = new System.Drawing.Size(183, 22);
            this.lnkLocal.TabIndex = 6;
            this.lnkLocal.TabStop = true;
            this.lnkLocal.Text = "本机图片(e:\\照片.jpg)";
            this.lnkLocal.UseCompatibleTextRendering = true;
            this.lnkLocal.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkLocal_LinkClicked);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
            this.ClientSize = new System.Drawing.Size(288, 244);
            this.Controls.Add(this.lnkLocal);
            this.Controls.Add(this.lnkgoogle);
            this.Controls.Add(this.lnk163);
            this.Controls.Add(this.lnkbaidu);
            this.Controls.Add(this.lnksina);
            this.Name = "Form1";
            this.Text = "打开网页或本机文件";
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void lnkOpen_LinkClicked(object sender,
			System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			lnksina.LinkVisited=true;
			//添加“using System.Diagnostics;”可以省略System.Diagnostics引导
			Process.Start(lnksina.Text.Substring(3,15));  
		}

		private void linClear_LinkClicked(object sender, 
			System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			lnkbaidu.LinkVisited=true;
			//lnkbaidu.Tag="www.baidu.com";
			Process.Start(lnkbaidu.Text.Substring(3,13));
		}

		private void lnk163_LinkClicked(object sender, 
			System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			lnk163.LinkVisited=true;
			Process.Start(lnk163.Text.Substring(3,11));
		}

		private void lnkgoogle_LinkClicked(object sender, 
			System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			lnkgoogle.LinkVisited=true;
			Process.Start(lnkgoogle.Text.Substring(7,14));
		}

		private void lnkLocal_LinkClicked(object sender, 
			System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			lnkLocal.LinkVisited=true;
			//lnkLocal.Tag="e:照片.jpg";
			Process.Start(lnkLocal.Text.Substring(5,9));
			//Process.Start(lnkLocal.Text.Substring(5,7));    e:1.qdt 无关联
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -