Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
BluePointLilac committed Aug 28, 2021
1 parent f8f530c commit 5b89cd8
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 18 deletions.
18 changes: 11 additions & 7 deletions ContextMenuManager/BluePointLilac.Controls/MyListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ public virtual void ClearItems()
{
if(this.Controls.Count == 0) return;
this.SuspendLayout();
foreach(Control control in this.Controls) BeginInvoke(new Action(control.Dispose));
this.Controls.Clear();
for(int i = this.Controls.Count - 1; i >= 0; i--)
{
Control ctr = this.Controls[i];
this.Controls.Remove(ctr);
ctr.Dispose();
}
this.ResumeLayout();
}

Expand Down Expand Up @@ -154,9 +158,9 @@ public MyListItem()
this.BackColor = Color.FromArgb(250, 250, 250);
this.Controls.AddRange(new Control[] { lblSeparator, flpControls, lblText, picImage });
this.Resize += (Sender, e) => pnlScrollbar.Height = this.ClientSize.Height;
flpControls.MouseClick += (sender, e) => this.OnMouseClick(null);
flpControls.MouseEnter += (sender, e) => this.OnMouseEnter(null);
flpControls.MouseDown += (sender, e) => this.OnMouseDown(null);
flpControls.MouseClick += (sender, e) => this.OnMouseClick(e);
flpControls.MouseEnter += (sender, e) => this.OnMouseEnter(e);
flpControls.MouseDown += (sender, e) => this.OnMouseDown(e);
lblSeparator.SetEnabled(false);
lblText.SetEnabled(false);
CenterControl(lblText);
Expand Down Expand Up @@ -263,8 +267,8 @@ public void AddCtr(Control ctr, int space)
this.SuspendLayout();
ctr.Parent = flpControls;
ctr.Margin = new Padding(0, 0, space, 0);
ctr.MouseEnter += (sender, e) => this.OnMouseEnter(null);
ctr.MouseDown += (sender, e) => this.OnMouseEnter(null);
ctr.MouseEnter += (sender, e) => this.OnMouseEnter(e);
ctr.MouseDown += (sender, e) => this.OnMouseEnter(e);
CenterControl(ctr);
this.ResumeLayout();
}
Expand Down
6 changes: 4 additions & 2 deletions ContextMenuManager/BluePointLilac.Controls/ReadOnlyTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public ReadOnlyTextBox()
this.ShortcutsEnabled = false;
this.BackColor = Color.White;
this.ForeColor = Color.FromArgb(80, 80, 80);
this.Font = new Font(SystemFonts.MenuFont.FontFamily, 10F);
this.Font = SystemFonts.MenuFont;
this.Font = new Font(this.Font.FontFamily, this.Font.Size + 1F);
}

const int WM_SETFOCUS = 0x0007;
Expand Down Expand Up @@ -48,7 +49,8 @@ public ReadOnlyRichTextBox()
this.BackColor = Color.White;
this.BorderStyle = BorderStyle.None;
this.ForeColor = Color.FromArgb(80, 80, 80);
this.Font = new Font(SystemFonts.MenuFont.FontFamily, 10F);
this.Font = SystemFonts.MenuFont;
this.Font = new Font(this.Font.FontFamily, this.Font.Size + 1F);
}

const int WM_SETFOCUS = 0x0007;
Expand Down
4 changes: 4 additions & 0 deletions ContextMenuManager/BluePointLilac.Methods/FormExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace BluePointLilac.Methods
public static class FormExtension
{
/// <summary>移动窗体时同时移动另一个窗体</summary>
/// <param name="frm1">主动移动的窗体</param>
/// <param name="frm2">同时被移动的窗体</param>
public static void MoveAsMove(this Form frm1, Form frm2)
{
if(frm2 == null) return;
Expand All @@ -21,6 +23,8 @@ public static void MoveAsMove(this Form frm1, Form frm2)
}

/// <summary>给窗体添加ESC键关闭功能</summary>
/// <param name="frm">指定窗口</param>
/// <param name="dr">关闭窗口时的对话框返回值</param>
/// <remarks>也可以重写Form的ProcessDialogKey事件,
/// 这个方法更简单,但遍历窗体控件时切记多了一个不可见的关闭按钮</remarks>
public static void AddEscapeButton(this Form frm, DialogResult dr = DialogResult.Cancel)
Expand Down
4 changes: 2 additions & 2 deletions ContextMenuManager/Controls/EnhanceMenusItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private static string CreateCommandFile(XmlNode xe)

sealed class EnhanceShellExItem : FoldSubItem, IChkVisibleItem
{
public string RegPath => $@"{ShellExPath}\ContextMenuHandlers\{DefaultKeyName}";
public string ShellExPath { get; set; }
public string DefaultKeyName { get; set; }
public Guid Guid { get; set; }
Expand All @@ -182,8 +183,7 @@ public bool ItemVisible
{
if(value)
{
string regPath = ObjectPath.GetNewPathWithIndex
($@"{ShellExPath}\ContextMenuHandlers\{DefaultKeyName}", ObjectPath.PathType.Registry);
string regPath = ObjectPath.GetNewPathWithIndex(this.RegPath, ObjectPath.PathType.Registry);
Registry.SetValue(regPath, "", this.Guid.ToString("B"));
}
else
Expand Down
5 changes: 4 additions & 1 deletion ContextMenuManager/Controls/FoldSubItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public FoldGroupItem(string groupPath, PathType pathType)
this.Font = new Font(this.Font, FontStyle.Bold);
this.AddCtrs(new[] { btnFold, btnOpenPath });
this.ContextMenuStrip.Items.AddRange(new[] { tsiFoldAll, tsiUnfoldAll });
this.MouseDown += (sender, e) => Fold();
this.MouseDown += (sender, e) =>
{
if(e.Button == MouseButtons.Left) Fold();
};
btnFold.MouseDown += (sender, e) =>
{
Fold();
Expand Down
1 change: 1 addition & 0 deletions ContextMenuManager/Controls/NewShellDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ sealed class NewShellForm : NewItemForm

static readonly string[] DirScenePaths = {
ShellList.MENUPATH_DIRECTORY,
ShellList.MENUPATH_BACKGROUND,
$@"{ShellList.SYSFILEASSPATH}\Directory."
};
static readonly string[] FileObjectsScenePaths = {
Expand Down
3 changes: 2 additions & 1 deletion ContextMenuManager/Methods/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ public static DateTime LastCheckUpdateTime
}
catch
{
return DateTime.MinValue;
//返回文件上次修改时间
return new FileInfo(Application.ExecutablePath).LastWriteTime;
//return new FileInfo(Application.ExecutablePath).LastWriteTime;
}
}
set => SetGeneralValue("LastCheckUpdateTime", value.ToBinary());
Expand Down
3 changes: 2 additions & 1 deletion ContextMenuManager/Methods/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ private static void UpdateApp(bool isManual)
XmlNode bodyXN = root.SelectSingleNode("body");
string info = AppString.Message.UpdateInfo.Replace("%v1", appVer.ToString()).Replace("%v2", webVer.ToString());
info += "\r\n\r\n" + MachinedInfo(bodyXN.InnerText);
if(AppMessageBox.Show(info, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if(MessageBox.Show(info, AppString.General.AppName,
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
string netVer = Environment.Version > new Version(4, 0) ? "4.0" : "3.5";
XmlNode assetsXN = root.SelectSingleNode("assets");
Expand Down
7 changes: 3 additions & 4 deletions ContextMenuManager/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b89cd8

Please sign in to comment.