* 增加几个函数

This commit is contained in:
sunny 2020-12-15 15:29:32 +08:00
parent ae82b36d3f
commit 1f653fb053
5 changed files with 93 additions and 4 deletions

View File

@ -483,7 +483,6 @@ namespace Sunny.UI
return;
}
removeIndex.ConsoleWriteLine("removeIndex");
var menuItem = Helper[removeIndex];
bool showButton = menuItem == null || !menuItem.AlwaysOpen;
if (showButton)

View File

@ -528,4 +528,70 @@ namespace Sunny.UI
UINotifier.Show(desc, type, title, isDialog, timeout, inApp);
}
}
public static class FormEx
{
public static Form ShowFullMask(this Form form)
{
Point pt = SystemEx.GetCursorPos();
Rectangle screen = Screen.GetBounds(pt);
Form mask = new Form();
mask.FormBorderStyle = FormBorderStyle.None;
mask.BackColor = Color.FromArgb(0, 0, 0);
mask.Opacity = 0.5;
mask.ShowInTaskbar = false;
mask.StartPosition = FormStartPosition.Manual;
mask.Bounds = screen;
mask.TopMost = true;
mask.Show();
return mask;
}
public static Form ShowControlMask(this Control control)
{
bool topmost = false;
Form baseForm = control.RootForm();
if (baseForm != null)
{
topmost = baseForm.TopMost;
baseForm.TopMost = true;
Application.DoEvents();
}
Form mask = new Form();
mask.FormBorderStyle = FormBorderStyle.None;
mask.BackColor = Color.FromArgb(0, 0, 0);
mask.Opacity = 0.5;
mask.ShowInTaskbar = false;
mask.StartPosition = FormStartPosition.Manual;
mask.Bounds = control.Bounds;
mask.Tag = baseForm;
mask.Text = topmost.ToString();
var pt = control.LocationOnScreen();
mask.Left = pt.X;
mask.Top = pt.Y;
mask.Show();
mask.TopMost = true;
return mask;
}
public static void EndShow(this Form maskForm)
{
if (maskForm.Tag is Form form)
{
form.TopMost = maskForm.Text.ToBoolean();
}
}
public static void ShowInMask(this Form frm, Form maskForm)
{
frm.StartPosition = FormStartPosition.Manual;
frm.Left = maskForm.Left + (maskForm.Width - frm.Width) / 2;
frm.Top = maskForm.Top + (maskForm.Height - frm.Height) / 2;
frm.ShowInTaskbar = false;
frm.TopMost = true;
}
}
}

View File

@ -42,6 +42,30 @@ namespace Sunny.UI
timer.Start();
}
public static Point LocationOnScreen(this Control ctrl)
{
Point point = new Point(0, 0);
do
{
point.Offset(ctrl.Location);
ctrl = ctrl.Parent;
}
while (ctrl != null);
return point;
}
public static Form RootForm(this Control ctrl)
{
if (ctrl == null) return null;
while (ctrl.Parent != null)
{
ctrl = ctrl.Parent;
}
return ctrl as Form;
}
public static Form GetParentForm(this Control ctrl)
{
while (!IsForm(ctrl.Parent))
@ -77,7 +101,7 @@ namespace Sunny.UI
return (form.Height - form.ClientSize.Height) - form.BorderSize();
}
public static Point LocationOnClient(this Control c)
private static Point LocationOnClient(this Control c)
{
Point point = new Point(0, 0);
for (; c.Parent != null; c = c.Parent)

View File

@ -101,7 +101,7 @@ namespace Sunny.UI
/// http://about.me/AlekseyNagovitsyn
/// </remarks>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Enum)]
internal class DisplayTextAttribute : Attribute
public class DisplayTextAttribute : Attribute
{
/// <summary>
/// The default value for the attribute <c>DisplayTextAttribute</c>, which is an empty string

View File

@ -74,8 +74,8 @@ namespace Sunny.UI
{
Console.WriteLine("SeDebugPrivilege is now available");
}
CloseHandle(hToken);
Console.ReadLine();
}
public static void Suspend()