mirror of
https://github.com/BluePointLilac/ContextMenuManager.git
synced 2026-01-14 06:04:00 +08:00
优化部分代码
This commit is contained in:
@@ -8,19 +8,27 @@ namespace BluePointLilac.Methods
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ReleaseCapture();
|
||||
private const int WM_NCLBUTTONDOWN = 0xA1;
|
||||
private const int HT_CAPTION = 0x2;
|
||||
|
||||
/// <summary>使控件能够移动所属窗体</summary>
|
||||
/// <remarks>副作用:使用此方法将无法触发Click等事件</remarks>
|
||||
/// <param name="ctr">目标控件</param>
|
||||
public static void CanMoveForm(this Control ctr)
|
||||
{
|
||||
ctr.MouseDown += (sender, e) =>
|
||||
DateTime downTime = DateTime.MinValue;
|
||||
DateTime upTime = DateTime.MinValue;
|
||||
ctr.MouseDown += (sender, e) => downTime = DateTime.Now;
|
||||
ctr.MouseUp += (sender, e) => upTime = DateTime.Now;
|
||||
ctr.MouseMove += (sender, e) =>
|
||||
{
|
||||
if(e.Button == MouseButtons.Left && ctr.FindForm().WindowState == FormWindowState.Normal)
|
||||
foreach(DateTime time in new[] { downTime, upTime })
|
||||
{
|
||||
if((DateTime.Now - time).TotalMilliseconds < 20) return;
|
||||
}
|
||||
if(e.Button == MouseButtons.Left)
|
||||
{
|
||||
ReleaseCapture();
|
||||
SendMessage(ctr.FindForm().Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace BluePointLilac.Methods
|
||||
|
||||
public static Image ResizeImage(this Image image, int width, int height)
|
||||
{
|
||||
if(image.Width == width && image.Height == height) return image;
|
||||
Bitmap destImage = new Bitmap(width, height);
|
||||
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
|
||||
using(Graphics g = Graphics.FromImage(destImage))
|
||||
@@ -44,6 +45,7 @@ namespace BluePointLilac.Methods
|
||||
|
||||
public static Image ResizeImage(this Image image, double scale)
|
||||
{
|
||||
if(scale == 1) return image;
|
||||
int width = (int)(image.Width * scale);
|
||||
int height = (int)(image.Height * scale);
|
||||
return image.ResizeImage(width, height);
|
||||
@@ -51,6 +53,7 @@ namespace BluePointLilac.Methods
|
||||
|
||||
public static Image ResizeImage(this Image image, Size newSize)
|
||||
{
|
||||
if(newSize == image.Size) return image;
|
||||
return image.ResizeImage(newSize.Width, newSize.Height);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,10 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AppConfig.cs" />
|
||||
<Compile Include="AppDic.cs" />
|
||||
<Compile Include="BluePointLilac.Controls\HitTestMessage.cs" />
|
||||
<Compile Include="BluePointLilac.Controls\MyBorderForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BluePointLilac.Controls\MyToolTip.cs" />
|
||||
<Compile Include="BluePointLilac.Controls\ReadOnlyTextBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
|
||||
@@ -103,8 +103,9 @@ namespace ContextMenuManager.Controls
|
||||
{
|
||||
using(OpenFileDialog dlg = new OpenFileDialog())
|
||||
{
|
||||
dlg.Filter = $"{AppString.Dialog.Program}|*.exe;*.bat;*.cmd;*.pif;*.com;*.vbs;*.vbe;*.js;*.jse;*.wsf";
|
||||
dlg.Filter = $"{AppString.Dialog.Program}|*.exe;*.bat;*.cmd;*.vbs;*.vbe;*.js;*.jse;*.wsf";
|
||||
if(dlg.ShowDialog() != DialogResult.OK) return;
|
||||
Arguments = string.Empty;
|
||||
ItemText = Path.GetFileNameWithoutExtension(dlg.FileName);
|
||||
string extension = Path.GetExtension(dlg.FileName).ToLower();
|
||||
switch(extension)
|
||||
@@ -114,6 +115,7 @@ namespace ContextMenuManager.Controls
|
||||
case ".js":
|
||||
case ".jse":
|
||||
case ".wsf":
|
||||
chkSE.Checked = true;
|
||||
ItemFilePath = "wscript.exe";
|
||||
Arguments = dlg.FileName;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user