// COPYRIGHT (C) Tom. ALL RIGHTS RESERVED.
// THE AntdUI PROJECT IS AN WINFORM LIBRARY LICENSED UNDER THE Apache-2.0 License.
// LICENSED UNDER THE Apache License, VERSION 2.0 (THE "License")
// YOU MAY NOT USE THIS FILE EXCEPT IN COMPLIANCE WITH THE License.
// YOU MAY OBTAIN A COPY OF THE LICENSE AT
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE
// DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
// SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING PERMISSIONS AND
// LIMITATIONS UNDER THE License.
// GITEE: https://gitee.com/antdui/AntdUI
// GITHUB: https://github.com/AntdUI/AntdUI
// CSDN: https://blog.csdn.net/v_132
// QQ: 17379620
using System;
using System.Drawing;
using System.Windows.Forms;
namespace AntdUI
{
///
/// FloatButton 悬浮按钮
///
/// 悬浮按钮。
public static class FloatButton
{
///
/// FloatButton 悬浮按钮
///
/// 所属窗口
/// 按钮
/// 回调
public static Form? open(Form form, ConfigBtn[] btns, Action call)
{
return open(new Config(form, btns, call));
}
///
/// FloatButton 悬浮按钮
///
/// 所属窗口
/// 所属控件
/// 按钮
/// 回调
public static Form? open(Form form, Control content, ConfigBtn[] btns, Action call)
{
return open(new Config(form, btns, call)
{
Control = content
});
}
///
/// FloatButton 配置
///
/// 所属窗口
/// 按钮
/// 回调
public static Config config(Form form, ConfigBtn[] btns, Action call)
{
return new Config(form, btns, call);
}
///
/// FloatButton 配置
///
/// 所属窗口
/// 所属控件
/// 按钮
/// 回调
public static Config config(Form form, Control content, ConfigBtn[] btns, Action call)
{
return new Config(form, btns, call)
{
Control = content
};
}
///
/// FloatButton 悬浮按钮
///
/// 配置
public static Form? open(this Config config)
{
if (config.Form.IsHandleCreated)
{
if (config.Form.InvokeRequired)
{
Form? form = null;
config.Form.Invoke(new Action(() =>
{
form = open(config);
}));
return form;
}
var floatButton = new LayeredFormFloatButton(config);
floatButton.Show(config.Form);
return floatButton;
}
return null;
}
///
/// 配置
///
public class Config
{
///
/// 配置
///
/// 所属窗口
/// 按钮
/// 回调
public Config(Form form, ConfigBtn[] btns, Action call)
{
Form = form;
Btns = btns;
Call = call;
}
///
/// 所属窗口
///
public Form Form { get; set; }
///
/// 字体
///
public Font? Font { get; set; }
///
/// 所属控件
///
public Control? Control { get; set; }
///
/// 方向
///
public TAlign Align { get; set; } = TAlign.BR;
///
/// 是否垂直方向
///
public bool Vertical { get; set; } = true;
///
/// 是否置顶
///
public bool TopMost { get; set; }
///
/// 大小
///
public int Size { get; set; } = 40;
///
/// 边距X
///
public int MarginX { get; set; } = 24;
///
/// 边距Y
///
public int MarginY { get; set; } = 24;
///
/// 间距
///
public int Gap { get; set; } = 40;
///
/// 按钮列表
///
public ConfigBtn[] Btns { get; set; }
///
/// 点击回调
///
public Action Call { get; set; }
}
///
/// 配置 按钮
///
public class ConfigBtn : NotifyProperty, BadgeConfig
{
///
/// 配置 按钮
///
/// 名称
public ConfigBtn(string name)
{
Name = name;
}
///
/// 配置 按钮
///
/// 名称
/// 图标
public ConfigBtn(string name, Bitmap icon)
{
Name = name;
Icon = icon;
}
///
/// 配置 按钮
///
/// 名称
/// 标题/SVG
/// 是否SVG
public ConfigBtn(string name, string text, bool isSVG = false)
{
Name = name;
if (isSVG) IconSvg = text;
else Text = text;
}
///
/// 名称
///
public string Name { get; set; }
Color? fore;
///
/// 文字颜色
///
public Color? Fore
{
get => fore;
set
{
if (fore == value) return;
fore = value;
OnPropertyChanged("Fore");
}
}
Bitmap? icon;
///
/// 自定义图标
///
public Bitmap? Icon
{
get => icon;
set
{
if (icon == value) return;
icon = value;
OnPropertyChanged("Icon");
}
}
string? iconSvg;
///
/// 自定义图标SVG
///
public string? IconSvg
{
get => iconSvg;
set
{
if (iconSvg == value) return;
iconSvg = value;
OnPropertyChanged("IconSvg");
}
}
Size? iconSize;
///
/// 图标大小
///
public Size? IconSize
{
get => iconSize;
set
{
if (iconSize == value) return;
iconSize = value;
OnPropertyChanged("IconSize");
}
}
///
/// 文字及其它内容
///
public string? Text { get; set; }
///
/// 气泡的内容
///
public string? Tooltip { get; set; }
TTypeMini type = TTypeMini.Default;
///
/// 设置按钮类型
///
public TTypeMini Type
{
get => type;
set
{
if (type == value) return;
type = value;
OnPropertyChanged("Type");
}
}
///
/// 圆角
///
public int Radius { get; set; } = 6;
bool round = true;
///
/// 圆角样式
///
public bool Round
{
get => round;
set
{
if (round == value) return;
round = value;
OnPropertyChanged("Round");
}
}
string? badge;
///
/// 徽标文本
///
public string? Badge
{
get => badge;
set
{
if (badge == value) return;
badge = value;
OnPropertyChanged("Badge");
}
}
///
/// 徽标大小
///
public float BadgeSize { get; set; } = 9F;
///
/// 徽标背景颜色
///
public Color? BadgeBack { get; set; }
#region 内部
internal bool hover = false;
internal Rectangle rect;
internal Rectangle rect_read;
internal Rectangle rect_icon;
internal Bitmap? shadow_temp = null;
#endregion
}
}
}