🦄 Beautiful AntdUI

This commit is contained in:
Tom
2026-01-18 13:48:13 +08:00
parent 693b8b2e31
commit 00428d84e4
11 changed files with 177 additions and 134 deletions

View File

@@ -21,7 +21,7 @@ namespace Demo.Controls
private void button1_Click(object sender, EventArgs e)
{
AntdUI.Notification.info(form, "Notification " + button1.Text, "Hello, Ant Design!", AntdUI.TAlignFrom.TL, Font, null, Color.Black, Color.WhiteSmoke);
AntdUI.Notification.info(form, "Notification " + button1.Text, "Hello, Ant Design!", AntdUI.TAlignFrom.TL, Font);
}
private void button2_Click(object sender, EventArgs e)
@@ -40,7 +40,7 @@ namespace Demo.Controls
private void button3_Click(object sender, EventArgs e)
{
AntdUI.Notification.info(form, "Notification " + button3.Text, "Hello, Ant Design!", AntdUI.TAlignFrom.BL, Font, null, Color.Yellow, null);
AntdUI.Notification.info(form, "Notification " + button3.Text, "Hello, Ant Design!", AntdUI.TAlignFrom.BL, Font);
}
private void button4_Click(object sender, EventArgs e)

View File

@@ -17,9 +17,6 @@ namespace Demo.Controls
{
form = _form;
InitializeComponent();
AntdUI.Config.ShadowOpacity = 0.35f;
AntdUI.Config.ShadowSize = 16;
}
private void button1_Click(object sender, EventArgs e)

View File

@@ -139,13 +139,7 @@ namespace AntdUI
shadow_temp?.Dispose();
shadow_temp = path.PaintShadowO(rect_client.Width, rect_client.Height, shadowColor ?? Colour.TextBase.Get(nameof(Panel), ColorScheme), shadow);
}
using (var attributes = new ImageAttributes())
{
var matrix = new ColorMatrix();
matrix.Matrix33 = shadowOpacity;
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(shadow_temp, new Rectangle(rect_client.X + shadowOffsetX, rect_client.Y + shadowOffsetY, rect_client.Width, rect_client.Height), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
}
g.Image(shadow_temp, new Rectangle(rect_client.X + shadowOffsetX, rect_client.Y + shadowOffsetY, rect_client.Width, rect_client.Height), shadowOpacity);
}
}

View File

@@ -9,7 +9,6 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Imaging;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
@@ -1080,15 +1079,11 @@ namespace AntdUI
}
if (shadow_dir_tmp.TryGetValue(id, out var shadow_temp))
{
using (var attributes = new ImageAttributes())
{
var matrix = new ColorMatrix();
if (it.AnimationHover) matrix.Matrix33 = it.AnimationHoverValue;
else if (it.Hover) matrix.Matrix33 = shadowOpacityHover;
else matrix.Matrix33 = shadowOpacity;
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(shadow_temp, new Rectangle(it.RECT_S.X + shadowOffsetX, it.RECT_S.Y + shadowOffsetY, it.RECT_S.Width, it.RECT_S.Height), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
}
float opacity;
if (it.AnimationHover) opacity = it.AnimationHoverValue;
else if (it.Hover) opacity = shadowOpacityHover;
else opacity = shadowOpacity;
g.Image(shadow_temp, new Rectangle(it.RECT_S.X + shadowOffsetX, it.RECT_S.Y + shadowOffsetY, it.RECT_S.Width, it.RECT_S.Height), opacity);
}
}
}

View File

@@ -350,6 +350,19 @@ namespace AntdUI
/// </summary>
public int? MaxWidth { get; set; }
#region
/// <summary>
/// 自定义背景色
/// </summary>
public Color? Back { get; set; }
/// <summary>
/// 自定义前景色
/// </summary>
public Color? Fore { get; set; }
#endregion
public void OK(string text)
{
Icon = TType.Success;
@@ -393,6 +406,17 @@ namespace AntdUI
return this;
}
public Config SetBack(Color? value)
{
Back = value;
return this;
}
public Config SetFore(Color? value)
{
Fore = value;
return this;
}
#region
public Config SetIcon(TType icon = TType.Success)
@@ -582,14 +606,14 @@ namespace AntdUI
internal class MessageFrm : ILayeredFormAnimate
{
internal Message.Config config;
int shadow_size = 10;
int shadow_size = 0;
public MessageFrm(Message.Config _config, string? id)
{
config = _config;
Tag = id;
if (config.TopMost) Helper.SetTopMost(Handle);
else config.Target.SetTopMost(Handle);
shadow_size = (int)(shadow_size * Dpi);
if (Config.ShadowEnabled) shadow_size = (int)(Config.ShadowSize * Dpi);
loading = _config.Call != null;
config.Target.SetFontConfig(config.Font, this);
config.Target.SetIcon(this);
@@ -712,17 +736,25 @@ namespace AntdUI
Bitmap rbmp = new Bitmap(rect.Width, rect.Height);
using (var g = Graphics.FromImage(rbmp).High())
{
using (var path = DrawShadow(g, rect, rect_read))
using (var path = DrawShadow(g, rect, rect_read, out int radius))
{
g.Fill(Colour.BgElevated.Get(nameof(Message)), path);
g.Fill(config.Back ?? Colour.BgElevated.Get(name), path);
if (radius > -1)
{
int bor = (int)(Dpi), bor2 = bor * 2;
using (var path2 = new Rectangle(rect_read.X + bor, rect_read.Y + bor, rect_read.Width - bor2, rect_read.Height - bor2).RoundPath(radius))
{
g.Draw(Colour.BorderColor.Get(name), bor, path2);
}
}
}
if (loading)
{
var bor3 = 3F * Dpi;
g.DrawEllipse(Colour.Fill.Get(nameof(Message)), bor3, rect_loading);
g.DrawEllipse(Colour.Fill.Get(name), bor3, rect_loading);
if (AnimationLoadingValue > -1)
{
using (var pen = new Pen(Colour.Primary.Get(nameof(Message)), bor3))
using (var pen = new Pen(Colour.Primary.Get(name), bor3))
{
pen.StartCap = pen.EndCap = LineCap.Round;
g.DrawArc(pen, rect_loading, AnimationLoadingValue, 100);
@@ -731,7 +763,7 @@ namespace AntdUI
}
else if (config.IconCustom != null) g.PaintIcons(config.IconCustom, rect_icon);
else if (config.Icon != TType.None) g.PaintIcons(config.Icon, rect_icon, "Message", TAMode.Auto);
using (var brush = new SolidBrush(Colour.TextBase.Get(nameof(Message))))
using (var brush = new SolidBrush(config.Fore ?? Colour.TextBase.Get(name)))
{
g.DrawText(config.Text, Font, brush, rect_txt, s_f_left);
}
@@ -746,18 +778,21 @@ namespace AntdUI
/// <param name="g">GDI</param>
/// <param name="rect_client">客户区域</param>
/// <param name="rect_read">真实区域</param>
GraphicsPath DrawShadow(Canvas g, Rectangle rect_client, Rectangle rect_read)
GraphicsPath DrawShadow(Canvas g, Rectangle rect_client, Rectangle rect_read, out int r)
{
var path = rect_read.RoundPath((int)(config.Radius * Dpi));
if (Config.ShadowEnabled)
r = -1;
var radius = (int)(config.Radius * Dpi);
var path = rect_read.RoundPath(radius);
if (shadow_size > 0)
{
if (shadow_temp == null || (shadow_temp.Width != rect_client.Width || shadow_temp.Height != rect_client.Height))
{
shadow_temp?.Dispose();
shadow_temp = path.PaintShadow(rect_client.Width, rect_client.Height);
}
g.Image(shadow_temp.Bitmap, rect_client, .2F);
g.Image(shadow_temp.Bitmap, rect_client, Config.ShadowOpacity);
}
else r = radius;
return path;
}

View File

@@ -31,7 +31,7 @@ namespace AntdUI
/// <param name="align">位置</param>
/// <param name="font">字体</param>
/// <param name="autoClose">自动关闭时间0等于不关闭</param>
public static void success(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null, Color? back = null, Color? fore = null) => open(new Config(form, title, text, TType.Success, align, font, autoClose, back, fore));
public static void success(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null) => open(new Config(form, title, text, TType.Success, align, font, autoClose));
/// <summary>
/// 信息通知
@@ -42,7 +42,7 @@ namespace AntdUI
/// <param name="align">位置</param>
/// <param name="font">字体</param>
/// <param name="autoClose">自动关闭时间0等于不关闭</param>
public static void info(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null, Color? back = null, Color? fore = null) => open(new Config(form, title, text, TType.Info, align, font, autoClose, back, fore));
public static void info(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null) => open(new Config(form, title, text, TType.Info, align, font, autoClose));
/// <summary>
/// 警告通知
@@ -53,7 +53,7 @@ namespace AntdUI
/// <param name="align">位置</param>
/// <param name="font">字体</param>
/// <param name="autoClose">自动关闭时间0等于不关闭</param>
public static void warn(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null, Color? back = null, Color? fore = null) => open(new Config(form, title, text, TType.Warn, align, font, autoClose, back, fore));
public static void warn(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null) => open(new Config(form, title, text, TType.Warn, align, font, autoClose));
/// <summary>
/// 失败通知
@@ -64,7 +64,7 @@ namespace AntdUI
/// <param name="align">位置</param>
/// <param name="font">字体</param>
/// <param name="autoClose">自动关闭时间0等于不关闭</param>
public static void error(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null, Color? back = null, Color? fore = null) => open(new Config(form, title, text, TType.Error, align, font, autoClose, back, fore));
public static void error(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null) => open(new Config(form, title, text, TType.Error, align, font, autoClose));
/// <summary>
/// 普通通知
@@ -75,7 +75,7 @@ namespace AntdUI
/// <param name="align">位置</param>
/// <param name="font">字体</param>
/// <param name="autoClose">自动关闭时间0等于不关闭</param>
public static void open(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null, Color? back = null, Color? fore = null) => open(new Config(form, title, text, TType.None, align, font, autoClose, back, fore));
public static void open(Form form, string title, string text, TAlignFrom align = TAlignFrom.TR, Font? font = null, int? autoClose = null) => open(new Config(form, title, text, TType.None, align, font, autoClose));
/// <summary>
/// Notification 通知提醒框
@@ -166,11 +166,6 @@ namespace AntdUI
Icon = icon;
}
public Config(Target target, string title, string text, TType icon, TAlignFrom align, Font? font, int? autoClose)
: this(target, title, text, icon, align, font, autoClose, null, null) { }
public Config(Target target, string title, string text, TType icon, TAlignFrom align, Font? font, int? autoClose, Color? back)
: this(target, title, text, icon, align, font, autoClose, back, null) { }
public Config(Target target, string title, string text, TType icon, TAlignFrom align, Font? font, int? autoClose, Color? back, Color? fore)
{
Target = target;
Font = font;
@@ -179,8 +174,6 @@ namespace AntdUI
Align = align;
Icon = icon;
if (autoClose.HasValue) AutoClose = autoClose.Value;
Back = back;
Fore = fore;
}
#region
@@ -190,8 +183,6 @@ namespace AntdUI
public Config(Form form, string title, string text, TType icon, TAlignFrom align) : this(new Target(form), title, text, icon, align) { }
public Config(Form form, string title, string text, TType icon, TAlignFrom align, Font? font) : this(new Target(form), title, text, icon, align, font) { }
public Config(Form form, string title, string text, TType icon, TAlignFrom align, Font? font, int? autoClose) : this(new Target(form), title, text, icon, align, font, autoClose) { }
public Config(Form form, string title, string text, TType icon, TAlignFrom align, Font? font, int? autoClose, Color? back) : this(new Target(form), title, text, icon, align, font, autoClose, back) { }
public Config(Form form, string title, string text, TType icon, TAlignFrom align, Font? font, int? autoClose, Color? back, Color? fore) : this(new Target(form), title, text, icon, align, font, autoClose, back, fore) { }
#endregion
@@ -317,14 +308,20 @@ namespace AntdUI
/// 是否启用声音
/// </summary>
public bool EnableSound { get; set; }
#region
/// <summary>
/// 自定义背景色
/// </summary>
public Color? Back { get; set; }
public Color? Back { get; set; }
/// <summary>
/// 自定义前景色
/// </summary>
public Color? Fore { get; set; }
#endregion
#region
public Config SetID(string? value)
@@ -356,8 +353,18 @@ namespace AntdUI
LocalizationText = localization;
return this;
}
public Config SetBack(Color? value) { Back = value; return this; }
public Config SetFore(Color? value) { Fore = value; return this; }
public Config SetBack(Color? value)
{
Back = value;
return this;
}
public Config SetFore(Color? value)
{
Fore = value;
return this;
}
#region
public Config SetIcon(TType icon = TType.Success)
@@ -488,6 +495,11 @@ namespace AntdUI
/// </summary>
public string Text { get; set; }
/// <summary>
/// 文本颜色
/// </summary>
public Color? Fore { get; set; }
/// <summary>
/// 点击回调
/// </summary>
@@ -498,11 +510,20 @@ namespace AntdUI
/// </summary>
public object? Tag { get; set; }
#region
public ConfigLink SetFore(Color? value)
{
Fore = value;
return this;
}
public ConfigLink SetTag(object? value)
{
Tag = value;
return this;
}
#endregion
}
}
@@ -510,14 +531,14 @@ namespace AntdUI
{
Font font_title;
internal Notification.Config config;
int shadow_size = Config.ShadowSize;
int shadow_size = 0;
public NotificationFrm(Notification.Config _config, string? id)
{
config = _config;
Tag = id;
if (config.TopMost) Helper.SetTopMost(Handle);
else config.Target.SetTopMost(Handle);
shadow_size = (int)(shadow_size * Dpi);
if (Config.ShadowEnabled) shadow_size = (int)(Config.ShadowSize * Dpi);
config.Target.SetFontConfig(config.Font, this);
config.Target.SetIcon(this);
font_title = config.FontTitle ?? new Font(Font.FontFamily, Font.Size * 1.14F, config.FontStyleTitle ?? Font.Style);
@@ -578,9 +599,17 @@ namespace AntdUI
Bitmap rbmp = new Bitmap(rect.Width, rect.Height);
using (var g = Graphics.FromImage(rbmp).High())
{
using (var path = DrawShadow(g, rect, rect_read))
using (var path = DrawShadow(g, rect, rect_read, out int radius))
{
g.Fill(config.Back ?? Colour.BgElevated.Get(nameof(Notification)), path);
g.Fill(config.Back ?? Colour.BgElevated.Get(name), path);
if (radius > -1)
{
int bor = (int)(Dpi), bor2 = bor * 2;
using (var path2 = new Rectangle(rect_read.X + bor, rect_read.Y + bor, rect_read.Width - bor2, rect_read.Height - bor2).RoundPath(radius))
{
g.Draw(Colour.BorderColor.Get(name), bor, path2);
}
}
}
if (config.IconCustom != null) g.PaintIcons(config.IconCustom, rect_icon);
else if (config.Icon != TType.None) g.PaintIcons(config.Icon, rect_icon, "Notification", TAMode.Auto);
@@ -591,30 +620,31 @@ namespace AntdUI
{
using (var path = rect_close.RoundPath((int)(4 * Dpi)))
{
g.Fill(Helper.ToColor(close_button.Value, Colour.FillSecondary.Get(nameof(Notification))), path);
g.Fill(Helper.ToColor(close_button.Value, Colour.FillSecondary.Get(name)), path);
}
g.PaintIconClose(rect_close, Colour.Text.Get(nameof(Notification)), .6F);
g.PaintIconClose(rect_close, Colour.Text.Get(name), .6F);
}
else if (close_button.Switch)
{
using (var path = rect_close.RoundPath((int)(4 * Dpi)))
{
g.Fill(Colour.FillSecondary.Get(nameof(Notification)), path);
g.Fill(Colour.FillSecondary.Get(name), path);
}
g.PaintIconClose(rect_close, Colour.Text.Get(nameof(Notification)), .6F);
g.PaintIconClose(rect_close, Colour.Text.Get(name), .6F);
}
else g.PaintIconClose(rect_close, Colour.TextTertiary.Get(nameof(Notification)), .6F);
else g.PaintIconClose(rect_close, Colour.TextTertiary.Get(name), .6F);
}
using (var brush = new SolidBrush(config.Fore ?? Colour.TextBase.Get(nameof(Notification))))
using (var brush = new SolidBrush(config.Fore ?? Colour.TextBase.Get(name)))
{
g.DrawText(config.Title, font_title, brush, rect_title, s_f_left);
g.DrawText(config.Text, Font, brush, rect_txt, s_f_left_left);
}
if (config.Link != null)
{
using (var pen = new Pen(Colour.Primary.Get(nameof(Notification)), Dpi))
var linkcolor = config.Link.Fore ?? Colour.Primary.Get(name);
using (var pen = new Pen(linkcolor, Dpi))
{
g.DrawText(config.Link.Text, Font, Colour.Primary.Get(nameof(Notification)), rect_link_text, s_f);
g.DrawText(config.Link.Text, Font, linkcolor, rect_link_text, s_f);
g.DrawLines(pen, TAlignMini.Right.TriangleLines(rect_links));
}
}
@@ -629,10 +659,12 @@ namespace AntdUI
/// <param name="g">GDI</param>
/// <param name="rect_client">客户区域</param>
/// <param name="rect_read">真实区域</param>
GraphicsPath DrawShadow(Canvas g, Rectangle rect_client, Rectangle rect_read)
GraphicsPath DrawShadow(Canvas g, Rectangle rect_client, Rectangle rect_read, out int r)
{
var path = rect_read.RoundPath((int)(config.Radius * Dpi));
if (Config.ShadowEnabled)
r = -1;
var radius = (int)(config.Radius * Dpi);
var path = rect_read.RoundPath(radius);
if (shadow_size > 0)
{
if (shadow_temp == null || (shadow_temp.Width != rect_client.Width || shadow_temp.Height != rect_client.Height))
{
@@ -641,6 +673,7 @@ namespace AntdUI
}
g.Image(shadow_temp.Bitmap, rect_client, Config.ShadowOpacity);
}
else r = radius;
return path;
}
@@ -717,7 +750,7 @@ namespace AntdUI
{
if (config.CloseIcon)
{
close_button.MaxValue = Colour.FillSecondary.Get(nameof(Notification), TAMode.Auto).A;
close_button.MaxValue = Colour.FillSecondary.Get(name, TAMode.Auto).A;
close_button.Switch = rect_close.Contains(e.X, e.Y);
SetCursor(close_button.Switch);
if (close_button.Switch)

View File

@@ -447,15 +447,11 @@ namespace AntdUI
shadow_temp?.Dispose();
shadow_temp = path.PaintShadowO(rect_client.Width, rect_client.Height, shadowColor ?? Colour.TextBase.Get(nameof(Panel), ColorScheme), shadow);
}
using (var attributes = new ImageAttributes())
{
var matrix = new ColorMatrix();
if (AnimationHover) matrix.Matrix33 = AnimationHoverValue;
else if (ExtraMouseHover) matrix.Matrix33 = shadowOpacityHover;
else matrix.Matrix33 = shadowOpacity;
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(shadow_temp, new Rectangle(rect_client.X + shadowOffsetX, rect_client.Y + shadowOffsetY, rect_client.Width, rect_client.Height), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
}
float opacity;
if (AnimationHover) opacity = AnimationHoverValue;
else if (ExtraMouseHover) opacity = shadowOpacityHover;
else opacity = shadowOpacity;
g.Image(shadow_temp, new Rectangle(rect_client.X + shadowOffsetX, rect_client.Y + shadowOffsetY, rect_client.Width, rect_client.Height), opacity);
}
return path;
}

View File

@@ -20,7 +20,7 @@ namespace AntdUI
{
if (ShadowEnabled)
{
shadow = (int)(10 * Dpi);
shadow = (int)(Config.ShadowSize * Dpi);
shadow2 = shadow * 2;
}
}

View File

@@ -33,11 +33,14 @@ namespace AntdUI
};
}
}
int shadow_size = 0;
public LayeredFormDrawer(Drawer.Config _config)
{
config = _config;
topMost = config.Form.SetTopMost(Handle);
Font = config.Form.Font;
if (Config.ShadowEnabled) shadow_size = (int)(Config.ShadowSize * Dpi) * 2;
padding = (int)Math.Round(config.Padding * Dpi);
Padding = new Padding(padding);
HasBor = Helper.FormFrame(config.Form, out FrmRadius, out FrmBor);
@@ -46,8 +49,8 @@ namespace AntdUI
SetPoint();
SetSize(start_W, start_H);
SetLocation(start_X, start_Y);
if (vertical) tempContent = new Bitmap(end_W - padding * 2, end_H - 20 - padding * 2);
else tempContent = new Bitmap(end_W - 20 - padding * 2, end_H - padding * 2);
if (vertical) tempContent = new Bitmap(end_W - padding * 2, end_H - shadow_size - padding * 2);
else tempContent = new Bitmap(end_W - shadow_size - padding * 2, end_H - padding * 2);
if (config.Content.Tag is Size) { }
else
{
@@ -71,7 +74,7 @@ namespace AntdUI
case TAlignMini.Top:
vertical = true;
start_H = 0;
end_H = (int)(config.Content.Height * Dpi) + padding * 2 + 20;
end_H = (int)(config.Content.Height * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowT)
{
start_W = end_W = windowT.Width;
@@ -88,7 +91,7 @@ namespace AntdUI
case TAlignMini.Bottom:
vertical = true;
start_H = 0;
end_H = (int)(config.Content.Height * Dpi) + padding * 2 + 20;
end_H = (int)(config.Content.Height * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowB)
{
start_W = end_W = windowB.Width;
@@ -105,7 +108,7 @@ namespace AntdUI
break;
case TAlignMini.Left:
start_W = 0;
end_W = (int)(config.Content.Width * Dpi) + padding * 2 + 20;
end_W = (int)(config.Content.Width * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowL)
{
start_H = end_H = windowL.Height;
@@ -122,7 +125,7 @@ namespace AntdUI
case TAlignMini.Right:
default:
start_W = 0;
end_W = (int)(config.Content.Width * Dpi) + padding * 2 + 20;
end_W = (int)(config.Content.Width * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowR)
{
start_H = end_H = windowR.Height;
@@ -412,7 +415,7 @@ namespace AntdUI
switch (config.Align)
{
case TAlignMini.Top:
end_H = (int)(size.Height * Dpi) + padding * 2 + 20;
end_H = (int)(size.Height * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowT)
{
start_W = end_W = windowT.Width;
@@ -427,7 +430,7 @@ namespace AntdUI
}
break;
case TAlignMini.Bottom:
end_H = (int)(size.Height * Dpi) + padding * 2 + 20;
end_H = (int)(size.Height * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowB)
{
start_W = end_W = windowB.Width;
@@ -443,7 +446,7 @@ namespace AntdUI
end_Y = start_Y - end_H;
break;
case TAlignMini.Left:
end_W = (int)(size.Width * Dpi) + padding * 2 + 20;
end_W = (int)(size.Width * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowL)
{
start_H = end_H = windowL.Height;
@@ -459,7 +462,7 @@ namespace AntdUI
break;
case TAlignMini.Right:
default:
end_W = (int)(size.Width * Dpi) + padding * 2 + 20;
end_W = (int)(size.Width * Dpi) + padding * 2 + shadow_size;
if (config.Form is Window windowR)
{
start_H = end_H = windowR.Height;
@@ -505,11 +508,11 @@ namespace AntdUI
{
switch (config.Align)
{
case TAlignMini.Top: return new Rectangle(end_X + padding, end_Y + padding, end_W - padding * 2, end_H - 20 - padding * 2);
case TAlignMini.Bottom: return new Rectangle(end_X + padding, end_Y + padding + 20, end_W - padding * 2, end_H - 20 - padding * 2);
case TAlignMini.Left: return new Rectangle(end_X + padding, end_Y + padding, end_W - 20 - padding * 2, end_H - padding * 2);
case TAlignMini.Top: return new Rectangle(end_X + padding, end_Y + padding, end_W - padding * 2, end_H - shadow_size - padding * 2);
case TAlignMini.Bottom: return new Rectangle(end_X + padding, end_Y + padding + shadow_size, end_W - padding * 2, end_H - shadow_size - padding * 2);
case TAlignMini.Left: return new Rectangle(end_X + padding, end_Y + padding, end_W - shadow_size - padding * 2, end_H - padding * 2);
case TAlignMini.Right:
default: return new Rectangle(end_X + padding + 20, end_Y + padding, end_W - 20 - padding * 2, end_H - padding * 2);
default: return new Rectangle(end_X + padding + shadow_size, end_Y + padding, end_W - shadow_size - padding * 2, end_H - padding * 2);
}
}
@@ -663,83 +666,76 @@ namespace AntdUI
/// <param name="rect">客户区域</param>
Rectangle DrawShadow(Canvas g, Rectangle rect)
{
var matrix = new ColorMatrix { Matrix33 = 0.3F };
switch (config.Align)
if (shadow_size > 0)
{
case TAlignMini.Top:
if (Config.ShadowEnabled)
{
int size = shadow_size * 2, size2 = size * 2;
var matrix = new ColorMatrix { Matrix33 = Config.ShadowOpacity };
switch (config.Align)
{
case TAlignMini.Top:
if (shadow_temp == null || shadow_temp.Width != end_W)
{
shadow_temp?.Dispose();
using (var path = new Rectangle(rect.X, rect.Y + 20, end_W, 40).RoundPath(FrmRadius))
using (var path = new Rectangle(rect.X, rect.Y + shadow_size, end_W, size).RoundPath(FrmRadius))
{
shadow_temp = path.PaintShadow(end_W, 80, 20);
shadow_temp = path.PaintShadow(end_W, size2, shadow_size);
}
}
using (var attributes = new ImageAttributes())
{
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.Y, rect.Bottom - 80, rect.Width, 80), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.Y, rect.Bottom - size2, rect.Width, size2), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
}
}
return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height - 20);
case TAlignMini.Bottom:
if (Config.ShadowEnabled)
{
return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height - shadow_size);
case TAlignMini.Bottom:
if (shadow_temp == null || shadow_temp.Width != end_W)
{
shadow_temp?.Dispose();
using (var path = new Rectangle(rect.X, rect.Y + 20, end_W, 40).RoundPath(FrmRadius))
using (var path = new Rectangle(rect.X, rect.Y + shadow_size, end_W, size).RoundPath(FrmRadius))
{
shadow_temp = path.PaintShadow(end_W, 80, 20);
shadow_temp = path.PaintShadow(end_W, size2, shadow_size);
}
}
using (var attributes = new ImageAttributes())
{
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.Y, rect.Y, rect.Width, 80), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.Y, rect.Y, rect.Width, size2), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
}
}
return new Rectangle(rect.X, rect.Y + 20, rect.Width, rect.Height - 20);
case TAlignMini.Left:
if (Config.ShadowEnabled)
{
return new Rectangle(rect.X, rect.Y + shadow_size, rect.Width, rect.Height - shadow_size);
case TAlignMini.Left:
if (shadow_temp == null || shadow_temp.Height != end_H)
{
shadow_temp?.Dispose();
using (var path = new Rectangle(rect.X + 20, rect.Y, 40, end_H).RoundPath(FrmRadius))
using (var path = new Rectangle(rect.X + shadow_size, rect.Y, size, end_H).RoundPath(FrmRadius))
{
shadow_temp = path.PaintShadow(80, end_H, 20);
shadow_temp = path.PaintShadow(size2, end_H, shadow_size);
}
}
using (var attributes = new ImageAttributes())
{
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.Right - 80, rect.Y, 80, rect.Height), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.Right - size2, rect.Y, size2, rect.Height), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
}
}
return new Rectangle(rect.X, rect.Y, rect.Width - 20, rect.Height);
case TAlignMini.Right:
default:
if (Config.ShadowEnabled)
{
return new Rectangle(rect.X, rect.Y, rect.Width - shadow_size, rect.Height);
case TAlignMini.Right:
default:
if (shadow_temp == null || shadow_temp.Height != end_H)
{
shadow_temp?.Dispose();
using (var path = new Rectangle(rect.X + 20, rect.Y, 40, end_H).RoundPath(FrmRadius))
using (var path = new Rectangle(rect.X + shadow_size, rect.Y, size, end_H).RoundPath(FrmRadius))
{
shadow_temp = path.PaintShadow(80, end_H, 20);
shadow_temp = path.PaintShadow(size2, end_H, shadow_size);
}
}
using (var attributes = new ImageAttributes())
{
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.X, rect.Y, 80, rect.Height), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
g.Image(shadow_temp.Bitmap, new Rectangle(rect.X, rect.Y, size2, rect.Height), 0, 0, shadow_temp.Width, shadow_temp.Height, GraphicsUnit.Pixel, attributes);
}
}
return new Rectangle(rect.X + 20, rect.Y, rect.Width - 20, rect.Height);
return new Rectangle(rect.X + shadow_size, rect.Y, rect.Width - shadow_size, rect.Height);
}
}
return rect;
}
#endregion

View File

@@ -7,7 +7,6 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace AntdUI
@@ -338,12 +337,7 @@ namespace AntdUI
it.shadow_temp = path2.PaintShadowO(it.rect.Width, it.rect.Height, 14);
}
}
using (var attributes = new ImageAttributes())
{
var matrix = new ColorMatrix { Matrix33 = 0.2F };
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.Image(it.shadow_temp, new Rectangle(it.rect.X, it.rect.Y + 6, it.rect.Width, it.rect.Height), 0, 0, it.rect.Width, it.rect.Height, GraphicsUnit.Pixel, attributes);
}
g.Image(it.shadow_temp, new Rectangle(it.rect.X, it.rect.Y + (int)(4 * g.Dpi), it.rect.Width, it.rect.Height), it.rect, Config.ShadowOpacity);
}
return path;
}

View File

@@ -147,14 +147,17 @@ namespace AntdUI
/// 阴影使能
/// </summary>
public static bool ShadowEnabled { get; set; } = true;
/// <summary>
/// 阴影大小 (默认10DPI)
/// 阴影大小 (默认10像素)
/// </summary>
public static int ShadowSize { get; set; } = 10;
public static int ShadowSize { get; set; } = 10;
/// <summary>
/// 阴影透明度 (默认0.2f)
/// </summary>
public static float ShadowOpacity { get; set; } = 0.2F;
/// <summary>
/// 焦点边框使能
/// </summary>