private void btnAttach1_CheckedChanged(object sender, EventArgs e) { if (!File.Exists(FullFileName)) { return; } if (frmAttach1.IsDisposed) { frmAttach1 = new FormAttachment(); } if (btnAttch1.CheckState == CheckState.Checked) { frmAttach1.workpath = DirectoryCore.Get_AttachmentsDirectory(FullFileName); //frmAttach1.label1.Text = Path.GetFileName(fileListView1.selfilename) + " 的附件"; frmAttach1.TopLevel = false; frmAttach1.Bounds = htmEdit1.Bounds; frmAttach1.Parent = this;// frmAttach1.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right))); frmAttach1.Show(); } else { frmAttach1.Close(); } //updateAttachTitle(); htmEdit1.Visible = !btnAttch1.Checked; btnReadMode1.Enabled = !btnAttch1.Checked; winTextBox1.ReadOnly = btnAttch1.Checked; }
private void FormAttachment_FormClosed(object sender, FormClosedEventArgs e) { if (Directory.Exists(workpath) && DirectoryCore.IsEmpty(workpath)) { Directory.Delete(workpath); } }
private void 除_Click(object sender, EventArgs e) { //D:\Administrator\Desktop\MySpace\我的文件夹\回收站 //1在文件里 //2在回车站里 if (filename.IndexOf(recyclepath) != -1) { DialogResult d = MessageBox.Show("彻底删除文件夹: " + treeView1.SelectedNode.Text, "回收站", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == d) { Directory.Delete(filename, true); treeView1.SelectedNode.Remove(); } } else { if (!DirectoryCore.IsEmpty(filename)) { DialogResult d1 = MessageBox.Show("文件夹移到回收站: " + treeView1.SelectedNode.Text, "回收站", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == d1) { MoveToRecylebin(); } } else { MoveToRecylebin(); } } }
private void 新键_Click(object sender, EventArgs e) { string newdir = DirectoryCore.NewName(filename + "\\" + "新建文件夹"); //MessageBox.Show(newdir); Directory.CreateDirectory(newdir); TreeNode node = new TreeNode(Path.GetFileNameWithoutExtension(newdir)); treeView1.SelectedNode.Nodes.Add(node); treeView1.SelectedNode = node; 重命名_Click(sender, e); }
//重命名文件 private void winTextBox1_LostFocus(object sender, EventArgs e) { //RENAME //if (fileListView1.listView1.SelectedItems.Count == 1 // && File.Exists(fileListView1.selfilename)) string _htm = ".htm"; if (File.Exists(FullFileName)) { string source = FullFileName; string dest = Path.GetDirectoryName(source) + "\\" + winTextBox1.Text; if (!dest.EndsWith(_htm)) { dest += _htm; } if (!File.Exists(dest)) { string source_attachments = DirectoryCore.Get_AttachmentsDirectory(source); string dest_attachments = DirectoryCore.Get_AttachmentsDirectory(dest); string html = htmEdit1.DocumentText; string title = FileCore.GetHTMLTitleTag(html); if (title != "") { html = html.Replace(title, winTextBox1.Text); } File.WriteAllText(source, html, Encoding.UTF8); File.Move(source, dest); //移动_attachments if (Directory.Exists(source_attachments)) { Directory.Move(source_attachments, dest_attachments); } htmEdit1.htmlfilename = dest; FullFileName = dest; if (filelistview1 != null) { filelistview1.Refresh2(); } UpdateToolTips(); } } }
private void MoveToRecylebin() { string recyclePath1 = DirectoryCore.NewName(recyclepath + "\\" + treeView1.SelectedNode.Text); DirectoryInfo di = new DirectoryInfo(recyclePath1); Directory.Move(filename, recyclePath1); //只保证移到回收站也有右键菜单 TreeNode selnode = (TreeNode)treeView1.SelectedNode.Clone(); recyclebinNode.Nodes.Add(selnode); treeView1.SelectedNode.Remove(); selnode.Text = Path.GetFileNameWithoutExtension(recyclePath1); }
private void ToolStripMenuItems_Click(object sender, EventArgs e) { switch (((ToolStripMenuItem)sender).Name) { case "OpenWithNewTab1": OnOpenWithNewTab(sender, e); break; case "OpenWithInternet": Process.Start("iexplore.exe", selfilename); break; case "OpenWithExplorer": Process.Start("explorer.exe", @"/select," + selfilename); break; case "SaveAs": OnSaveAsClick(sender, e); break; case "NewFile": OnNewFileClick(sender, e); break; //复制文件 case "CopyAFile": { if (File.Exists(selfilename)) { string dest = FileCore.NewName(selfilename); File.Copy(selfilename, dest); AddItem(dest); //selfilename = dest; OnCopyFile(sender, e); //MessageBox.Show(selfilename); } break; } case "DeleteFiles": { if (selfilename.IndexOf(recylebin) != -1) { DialogResult d = MessageBox.Show("彻底删除 " + listView1.SelectedItems.Count + " 个的文件 ", "删除文件", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == d) { foreach (ListViewItem listItem in listView1.SelectedItems) { string filename = path + "\\" + listItem.Text + fileExt; File.Delete(filename); string source_attachments = DirectoryCore.Get_AttachmentsDirectory(filename); if (Directory.Exists(source_attachments)) { Directory.Delete(source_attachments, true); } listItem.Remove(); } } } else { foreach (ListViewItem listItem in listView1.SelectedItems) { string source = path + "\\" + listItem.Text + fileExt; string dest = recylebin + "\\" + listItem.Text + fileExt; #region 移动文件 _attachments dest = FileCore.NewName(dest); string html = File.ReadAllText(source, Encoding.UTF8); string title = FileCore.GetHTMLTitleTag(html); if (title != "") { html = html.Replace(title, listItem.Text); } File.WriteAllText(source, html, Encoding.UTF8); File.Move(source, dest); //移动_attachments string source_attachments = DirectoryCore.Get_AttachmentsDirectory(source); string dest_attachments = DirectoryCore.Get_AttachmentsDirectory(dest); if (Directory.Exists(dest_attachments)) { Directory.Delete(dest_attachments); } if (Directory.Exists(source_attachments)) { Directory.Move(source_attachments, dest_attachments); } #endregion listItem.Remove(); } } listView1.Refresh(); OnDeleteFile(sender, e); break; } case "RenameFile": OnRenameFileClick(sender, e); break; case "Refresh": Refresh2(); break; // 复制选中的标题 case "CopyTitle": { string s = ""; for (int i = 0; i < listView1.SelectedItems.Count; i++) { s += listView1.SelectedItems[i].Text + "\r\n"; } Clipboard.SetDataObject(s, true); break; } //复制完整路径 case "CopyFileName": { string s = ""; for (int i = 0; i < listView1.SelectedItems.Count; i++) { //if (listView1.SelectedIndices != null) { s += listView1.Items[i].SubItems[1].Text + "\r\n"; } } Clipboard.SetDataObject(s, true); break; } } }
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) { e.DrawBackground(); Rectangle itemRect = new Rectangle(e.Bounds.Left + 2, e.Bounds.Top + 1, e.Bounds.Width - 4 - 1, e.Bounds.Height - 2); //画线 e.Graphics.DrawLine(new Pen(new SolidBrush(Color.FromArgb(240, 240, 240))), new Point(itemRect.X, itemRect.Y + itemRect.Height), new Point(itemRect.X + itemRect.Width - 4, itemRect.Y + itemRect.Height)); //if (listView1.SelectedIndices.Count > 1) //{ // itemRect = new Rectangle(e.Bounds.Left + 3, // e.Bounds.Top, // e.Bounds.Width - 4, // e.Bounds.Height); //} //draw mouse move item back if (listViewItem1 != null && e.Item == listViewItem1 && NativeInterop.IsWinVista) { e.Graphics.FillRectangle(brush3, itemRect); e.Graphics.DrawRectangle(pen3, itemRect); //listView1.Refresh(); } //focusd item if ((e.State & ListViewItemStates.Focused) != 0) { e.Graphics.DrawRectangle(pen1, itemRect); focusedListViewItem1 = e.Item; } //draw selected item if (e.Item.Selected) { if (listView1.Focused) { e.Graphics.FillRectangle(brush1, itemRect); e.Graphics.DrawRectangle(pen1, itemRect); } else { e.Graphics.FillRectangle(brush2, itemRect); e.Graphics.DrawRectangle(pen2, itemRect); } } Size size = TextRenderer.MeasureText(e.Item.Text, listView1.Font); //text Rectangle textRect = new Rectangle(e.Item.Bounds.Left + 16 + 8, e.Item.Bounds.Top + size.Height / 2 - 2, e.Item.Bounds.Width - 50, 20); //e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Red)), textRect); e.Graphics.DrawString(e.Item.Text, listView1.Font, new SolidBrush(listView1.ForeColor), textRect); //HTML Icon Rectangle imgRect = new Rectangle(4, e.Item.Bounds.Top + 8, 16, 16); e.Graphics.DrawImage(pictureBox1.Image, imgRect); //e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), imgRect); //ATTACH IMG //string filename = path + "\\" + e.Item.Text + fileExt; //listView1.Items[Index].SubItems[1].Text = filename; string attachdir = DirectoryCore.Get_AttachmentsDirectory(e.Item.SubItems[1].Text); if (Directory.Exists(attachdir)) { Rectangle attachRect = new Rectangle(e.Bounds.Right - 22, e.Item.Bounds.Top + 8, 16, 16); e.Graphics.DrawImage(pictureBox2.Image, attachRect); //e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), attachRect); } }
private void treeView1_DragDrop(object sender, DragEventArgs e) { #region LISTVIEW 拖拽到TREEVIEW上 if (e.Data.GetDataPresent(typeof(ListView.SelectedListViewItemCollection).ToString(), false)) { Point loc = ((TreeView)sender).PointToClient(new Point(e.X, e.Y)); TreeNode destNode1 = ((TreeView)sender).GetNodeAt(loc); ListView.SelectedListViewItemCollection lstViewColl = (ListView.SelectedListViewItemCollection)e.Data.GetData(typeof(ListView.SelectedListViewItemCollection)); foreach (ListViewItem lvItem in lstViewColl) { string source = filename + "\\" + lvItem.Text; if (!source.EndsWith(".htm")) { source += ".htm"; } string dest = rootpath + "\\" + destNode1.FullPath + "\\" + lvItem.Text; if (!dest.EndsWith(".htm")) { dest += ".htm"; } if (filename == rootpath + "\\" + destNode1.FullPath) { MessageBox.Show("源文件和目标不能是同一个文件"); return; } dest = FileCore.NewName(dest); string html = File.ReadAllText(source, Encoding.UTF8); string title = FileCore.GetHTMLTitleTag(html); if (title != "") { html = html.Replace(title, Path.GetFileNameWithoutExtension(dest)); } File.WriteAllText(source, html, Encoding.UTF8); //移动文件 File.Move(source, dest); //移动_attachments string source_attachments = DirectoryCore.Get_AttachmentsDirectory(source); string dest_attachments = DirectoryCore.Get_AttachmentsDirectory(dest); if (Directory.Exists(dest_attachments.ToLower())) { Directory.Delete(dest_attachments); } if (Directory.Exists(source_attachments.ToLower())) { Directory.Move(source_attachments, dest_attachments); } lvItem.Remove(); } } #endregion #region TreeView自己的拖拽 destNode = treeView1.GetNodeAt(treeView1.PointToClient(new Point(e.X, e.Y))); string destNodeText = rootpath + "\\" + destNode.FullPath; if (selNode != destNode && (selNode.Parent != destNode)) { //文件 拖拽 到文件夹中 if (File.Exists(filename) && Directory.Exists(destNodeText)) { string destfile = FileCore.NewName(rootpath + "\\" + destNode.FullPath + "\\" + selNode.Text); if (filename == destfile) { MessageBox.Show("源文件和目标不能是同一个文件"); return; } string html = File.ReadAllText(filename, Encoding.UTF8); string title = FileCore.GetHTMLTitleTag(html); if (title != "") { html = html.Replace(title, Path.GetFileNameWithoutExtension(destfile)); } File.WriteAllText(filename, html, Encoding.UTF8); File.Move(filename, destfile); TreeNode selnode = (TreeNode)treeView1.SelectedNode.Clone(); destNode.Nodes.Add(selnode); DirectoryInfo di = new DirectoryInfo(destfile); selnode.Text = Path.GetFileName(di.Name); treeView1.SelectedNode.Remove(); destNode.Expand(); //移动_attachments string source_attachments = DirectoryCore.Get_AttachmentsDirectory(filename); string dest_attachments = DirectoryCore.Get_AttachmentsDirectory(destfile); if (Directory.Exists(dest_attachments.ToLower())) { Directory.Delete(dest_attachments); } if (Directory.Exists(source_attachments.ToLower())) { Directory.Move(source_attachments, dest_attachments); } } //文件夹 拖拽 到文件夹中 if (Directory.Exists(filename) && Directory.Exists(destNodeText)) { string destpath = DirectoryCore.NewName(rootpath + "\\" + destNode.FullPath + "\\" + selNode.Text); Directory.Move(filename, destpath); //if (selNode.Parent == null) // treeView1.Nodes.Remove(selNode); //else // selNode.Parent.Nodes.Remove(selNode); TreeNode selnode = (TreeNode)treeView1.SelectedNode.Clone(); destNode.Nodes.Add(selnode); DirectoryInfo di = new DirectoryInfo(destpath); selnode.Text = Path.GetFileNameWithoutExtension(di.Name); treeView1.SelectedNode.Remove(); destNode.Expand(); } } #endregion }