今年七月份刚大学毕业,属于技术小白,出来工作还算安逸,每月的大洋还是能够解决个人温饱的,但考虑到以后的发展,必须掌握一技之长,方可更好的生存。所以想在工作之余学习一下C#和一些数据库类的知识。并同步做学习笔记,以便温故。
今天学习掌握了3个命令控件,分别为:Button,LinkLabel,NotifyIcon。
Button:windows窗体的Button控件允许用户通过单击来执行操作。
LinkLabel:winodows窗体的LinkLabel控件使你可以向Windows窗体应用程序中添加web样式的链接。
NotifyIcon:Windows窗体的NotifyIcon组件通常用于显示在后台运行的进程的图标。
今天参考书本,做了一个窗体应用程序,如图:
第一步:创建Windows窗体应用程序项目,在Form1上分别添加Button,LinkLabel,NotifyIcon控件,并完成简单布局。
第二步:单击Button,在属性窗口对Text的属性进行命名修改,其他的Button同理。
第三步:单击添加的LinkLabel,在属性窗口将Text属性设置为“欢迎访问NFCP”,将LinkArea属性设置为“4,4”(因为缩写NFCP,在左起第4个字后,且长度为4),将NotifyIconTipIcon属性设置为Info(将在系统任务栏里显示图标),BallonTipText设置为“双击下面的图标打开程序主窗口”(气泡提醒的内容),BallonTipTittle设置为“温馨提示”(气泡提醒的标题),Icon设置为一个图标文件(ico文件可以网上下载或者用软件自制),Text设置为“应用示例正在运行”(此处也可自定义图标的名称)。
第四步:在代码编辑器中打开源文件Form1.cs然后编写事件的处理程序,我的处理程序如下:
namespace 小工具练习
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide(); //隐藏窗口
this.notifyIcon1.Visible = true; //判断是否显示在后台运行进程的图标
this.notifyIcon1.ShowBalloonTip(6000); //设置气泡提示,指定6秒后关闭
System.Diagnostics.Process.Start("http://www.fujitsu-nfcp.com/"); //调用外部程序
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(6000);
System.Diagnostics.Process.Start("http://fushitong.jd.com/");
}
private void button3_Click(object sender, EventArgs e)
{
this.Hide();
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(6000);
System.Diagnostics.Process.Start("http://shop.suning.com/30000152/index.html");
}
private void button4_Click(object sender, EventArgs e)
{
this.Hide();
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(6000);
System.Diagnostics.Process.Start("http://qjbgyp.tmall.com/");
}
private void button5_Click(object sender, EventArgs e)
{
this.Hide();
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(6000);
System.Diagnostics.Process.Start("http://www.dayinjiqudong.com");
}
private void button6_Click(object sender, EventArgs e)
{
this.Hide();
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(6000);
System.Diagnostics.Process.Start("http://www.fujitsu-nfcp.com/product/haocai/");
}
private void button7_Click(object sender, EventArgs e)
{
this.Hide();
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(6000);
System.Diagnostics.Process.Start("http://www.fujitsu-nfcp.com/service/");
}
private void button8_Click(object sender, EventArgs e)
{
this.Hide();
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(6000);
System.Diagnostics.Process.Start("http://www.fujitsu-nfcp.com/plus/list.php?tid=11");
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
VisitLink();
}
catch (Exception)
{
MessageBox.Show("Unable to open link that was clicked");
}
}
private void VisitLink()
{
linkLabel1.LinkVisited = true;
System.Diagnostics.Process.Start("http://www.fujitsu-nfcp.com/");
}
}
}
第五步:点击保存,按F6调试,按F5运行。
第六步:如果你运行后的窗口不居中,可以单击Form1窗体,将CenterScreen设置为CenterScreen即可。
运行后点击按钮窗体会隐藏,并且打开相应链接,任务栏的图标如下:
小白笔记,如有错误,谢谢指出!