Winform设计-小百货 涵盖基础插件学习(适合新手)
Winform设计-小百货 涵盖基础插件学习(适合新手)
第一次写winform,主要是为了加快对 事件的 理解。
代码如下:
private void Form1_Load(object sender, EventArgs e)
{
//FORM1
this.MaximizeBox = false;//限制最大化
this.Text = "小百货 By Mr.w";
//选项卡控件
tabControl1.Appearance = TabAppearance.FlatButtons;
tabPage1.Text="工具集";
tabPage2.Text = "文本编辑";
tabPage3.Text = "图像处理";
tabPage4.Text = "个人笔记";
tabPage5.Text = "网络类";
tabPage6.Text = "办公类";
//列表视图控件
listView1.Items.Add("360安全卫士");
listView1.Items.Add("Wireshark");
listView1.Items.Add("GNS3");
listView1.Items.Add("FlashXp");
listView1.LargeImageList = imageList1;
listView1.Items[0].ImageIndex = 0;
listView1.Items[1].ImageIndex = 1;
listView1.Items[2].ImageIndex = 2;
listView1.Items[3].ImageIndex = 3;
//打开和另存为
openFileDialog1.Filter = "txt文件(*.txt)|*.txt";
openFileDialog1.InitialDirectory = @"C:\Documents and Settings\cisco\桌面";
openFileDialog1.FileName =string.Empty;//打开按钮 默认显示文件名
saveFileDialog1.Filter = "txt文件(*.txt)|*.txt";
saveFileDialog1.InitialDirectory = @"D:\";
saveFileDialog1.CheckFileExists = false;
saveFileDialog1.CheckPathExists = false;
richTextBox1.ReadOnly = true;//只读
}
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
}
private void listView1_DoubleClick(object sender, EventArgs e)//双击事件
{
if (listView1.Items[0].Selected)//
{
Process.Start(@"C:\Program Files\360\360Safe\360Safe.exe");
}
if (listView1.Items[1].Selected)//
{
Process.Start(@"D:\wireshark\wireshark.exe");
}
/*
* 下面类似
*
*/
}
private void button1_Click(object sender, EventArgs e)//打开 事件
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader fileRead = new StreamReader(openFileDialog1.FileName,Encoding.Default);
richTextBox1.Text = fileRead.ReadToEnd();
fileRead.Close();
}
}
private void button2_Click(object sender, EventArgs e)//另存为 事件
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamWriter fileWriter = new StreamWriter(saveFileDialog1.FileName);
fileWriter.Write(richTextBox1.Text);
fileWriter.Close();
}
}