📄 frmdir.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Text ;
using System.IO;
using System.Data;
namespace SkyMail
{
/// <summary>
/// Frmdir 的摘要说明。
/// </summary>
public class Frmdir : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ImageList imageList1;
private System.ComponentModel.IContainer components;
private int nodes;
public Frmdir()//将前面的form选中的文件夹传递到本form作为默认选中
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Frmdir));
this.treeView1 = new System.Windows.Forms.TreeView();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// treeView1
//
this.treeView1.ImageList = this.imageList1;
this.treeView1.Location = new System.Drawing.Point(8, 56);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("本地文件夹", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("收件箱", 9, 9),
new System.Windows.Forms.TreeNode("发件箱", 10, 10),
new System.Windows.Forms.TreeNode("已发送邮件", 11, 11),
new System.Windows.Forms.TreeNode("垃圾箱", 12, 12)})});
this.treeView1.Size = new System.Drawing.Size(256, 216);
this.treeView1.TabIndex = 1;
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 16);
this.label1.TabIndex = 2;
this.label1.Text = "新文件夹名称";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(280, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 4;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(280, 56);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 24);
this.button2.TabIndex = 5;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// Frmdir
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(352, 277);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1,
this.textBox1,
this.label1,
this.treeView1});
this.Name = "Frmdir";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "创建新文件夹";
this.Load += new System.EventHandler(this.Frmdir_Load);
this.ResumeLayout(false);
}
#endregion
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void Frmdir_Load(object sender, System.EventArgs e)
{
treeView1.ExpandAll();
///<summary>
///需要先判断用户是否自定义文件夹
///<summary>
FileInfo s=new FileInfo("user.dr");
if(s.Exists)
{
StreamReader sr=new StreamReader(@"user.dr",Encoding.GetEncoding("GB2312"));
string con=sr.ReadToEnd();
sr.Close();
if (con.Trim().Length >0)
{
string[] fdir=con.Trim().Split(new char[]{'\n'});
for(int h=0;h<fdir.Length;h++ )
{
string[] fcon=fdir[h].Split((char)92);
string parstr=fcon[0].Trim();
string childstr=fcon[1].Trim();
// //循环判断选中哪个节点
for(int i=0;i<treeView1.Nodes.Count ;i++)
{
for(int j=0;j<treeView1.Nodes[i].Nodes.Count;j++)
{
if(treeView1.Nodes[i].Nodes[j].Text.IndexOf(parstr)!=-1)
{
treeView1.Nodes[i].Nodes[j].Nodes.Add(childstr);
break;
}
}
if(treeView1.Nodes[i].Text.IndexOf(parstr)!=-1)
{
treeView1.Nodes[i].Nodes.Add(childstr);
break;
}
}
}
}
}
}
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
}
//将用户自定义文件夹写入配置文件
private void button1_Click(object sender, System.EventArgs e)
{
if(textBox1.Text !="")
{
StreamWriter sw=new StreamWriter(@"user.dr",true,Encoding.GetEncoding("GB2312"));
string con=treeView1.SelectedNode.Text +(char)92+textBox1.Text+"\r\n";
string[] f=con.Trim().Split((char)92);
string parstr=f[0];
string childstr=f[1];
for(int i=0;i<treeView1.Nodes.Count;i++)
{
if(treeView1.Nodes[i].Text.Equals(parstr)) //如果第一层就已经找到了父节点,则判断有没有重名的文件夹
{
int ff=0;
for(int r=0;r<treeView1.Nodes[i].Nodes.Count;r++)
{
if(treeView1.Nodes[i].Nodes[r].Text.Equals(childstr))
{
MessageBox.Show("您输入的文件夹名称已经存在!");
ff=1;
break;
}
}
if(ff==0)
{
treeView1.Nodes[i].Nodes.Add(childstr);
string fname="";
fname=childstr.Trim() + "0"+".wg";
FileInfo g=new FileInfo(fname);
if(g.Exists)
{
DialogResult d=MessageBox.Show("已经存在这个文件夹,请确认是否重新创建该文件夹!","Sky软件",MessageBoxButtons.YesNo);
if(d==DialogResult.Yes)
{
sw.Write(con);
sw.Close();
g.Delete();
g.Refresh();
g.Create();
this.Dispose();
}
else
{
treeView1.Nodes[i].Nodes.RemoveAt(treeView1.Nodes[i].Nodes.Count-1);
break;
}
}
else
{
sw.Write(con);
sw.Close();
g.Create();
g.Refresh();
this.Dispose();
}
}
break;
}
for(int j=0;j<treeView1.Nodes[i].Nodes.Count;j++)
{
if(treeView1.Nodes[i].Nodes[j].Text.Equals(parstr))
{
//比较当前子树有没有名称相同的文件夹有则提示
int ff=0;
for(int r=0;r<treeView1.Nodes[i].Nodes[j].Nodes.Count;r++)
{
if(treeView1.Nodes[i].Nodes[j].Nodes[r].Text.Equals(childstr))
{
MessageBox.Show("您输入的文件夹名称已经存在!");
ff=1;
break;
}
}
if(ff==0)
{
treeView1.Nodes[i].Nodes[j].Nodes.Add(childstr);
string fname="";
fname=childstr.Trim() + "1"+".wg";
FileInfo g1=new FileInfo(fname);
if(g1.Exists)
{
DialogResult d=MessageBox.Show("已经存在这个文件夹,请确认是否重新创建该文件夹!","Sky软件",MessageBoxButtons.YesNo);
if(d==DialogResult.Yes)
{
sw.Write(con);
sw.Close();
g1.Delete();
g1.Refresh();
g1.Create();
}
else
{
treeView1.Nodes[i].Nodes[j].Nodes.RemoveAt(treeView1.Nodes[i].Nodes[j].Nodes.Count-1);
break;
}
}
else
{
sw.Write(con);
sw.Close();
g1.Create();
}
}
break;
}
}
}
}
else
{
MessageBox.Show ("您没有输入新文件夹的名称!");
textBox1.Focus();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -