antdui-demo/Views/ButtonDemo.cs
czz_y da365f11f9 国际化支持中,目前已支持首页,Button按钮,FloatButon按钮,Icon图标
In the internationalization support, the homepage, button, FloatButon button, and Icon icon are currently supported
2025-01-17 16:36:53 +08:00

137 lines
5.5 KiB
C#

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AntdUIDemo.Views
{
public partial class ButtonDemo : UserControl
{
private AntdUI.TooltipComponent tooltipComponent = new AntdUI.TooltipComponent()
{
Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))),
};
public ButtonDemo()
{
InitializeComponent();
// 遍历窗体中的所有控件并绑定 tooltip
BindButtonWithToolTip(this);
BindEventHandler();
}
private void BindEventHandler()
{
button_toggle.Click += Button_toggle_Click;
button_toggle2.Click += Button_toggle_Click;
button_toggle3.Click += Button_toggle_Click;
}
private void Button_toggle_Click(object sender, EventArgs e)
{
var button = (AntdUI.Button)sender;
button.Toggle = !button.Toggle;
BindButtonWithToolTip(this);
}
private void BindButtonWithToolTip(Control parent)
{
foreach (Control control in parent.Controls)
{
if (control is AntdUI.Button button)
{
var type = button.Type;
float borderwidth = button.BorderWidth;
int radius = button.Radius;
int wavesize = button.WaveSize;
var shape = button.Shape;
bool ghost = button.Ghost;
bool showarrow = button.ShowArrow;
bool joinleft = button.JoinLeft;
bool joinright = button.JoinRight;
var iconsvg = button.IconSvg;
var backactive = button.BackActive;
var backentend = button.BackExtend;
var backhover = button.BackHover;
var toggle = button.Toggle;
var toggletype = button.ToggleType;
var toggleiconsvg = button.ToggleIconSvg;
var loading = button.Loading;
var loadingvalue = button.LoadingValue;
var loadingwavecolor = button.LoadingWaveColor;
var loadingwavecount = button.LoadingWaveCount;
var loadingwavesize = button.LoadingWaveSize;
var loadingwavevalue = button.LoadingWaveValue;
var loadingwavevertical = button.LoadingWaveVertical;
// 构建SetTip文本
var tooltipText = new StringBuilder();
tooltipText.AppendLine($"Type: {type}");
tooltipText.AppendLine($"BorderWidth: {borderwidth}");
tooltipText.AppendLine($"Radius: {radius}");
tooltipText.AppendLine($"Wavesize: {wavesize}");
tooltipText.AppendLine($"Shape: {shape}");
if (ghost)
{
tooltipText.AppendLine($"Ghost: {ghost}");
}
if (showarrow)
{
tooltipText.AppendLine($"ShowArrow: {showarrow}");
}
if (joinleft)
{
tooltipText.AppendLine($"JoinLeft: {joinleft}");
}
if (joinright)
{
tooltipText.AppendLine($"JoinRight: {joinright}");
}
if (!string.IsNullOrEmpty(iconsvg))
{
tooltipText.AppendLine($"IconSvg: See IconSvg Properties");
}
if (backactive != null)
{
tooltipText.AppendLine($"BackActive: {backactive}");
}
if (!string.IsNullOrEmpty(backentend))
{
tooltipText.AppendLine($"BackExtend: {backentend}");
}
if (backhover != null)
{
tooltipText.AppendLine($"BackHover: {backhover}");
}
if (toggle)
{
tooltipText.AppendLine($"Toggle: {toggle}");
if (toggletype != null)
tooltipText.AppendLine($"ToggleType: {toggletype}");
if (!string.IsNullOrEmpty(toggleiconsvg))
{
tooltipText.AppendLine($"ToggleIconSvg: See ToggleIconSvg Properties");
}
}
if (loading)
{
tooltipText.AppendLine($"Loading: {loading}");
tooltipText.AppendLine($"LoadingWaveColor:{loadingwavecolor}");
tooltipText.AppendLine($"LoadingWaveCount:{loadingwavecount}");
tooltipText.AppendLine($"LoadingWaveSize:{loadingwavesize}");
tooltipText.AppendLine($"LoadingWaveValue:{loadingwavevalue}");
tooltipText.AppendLine($"LoadingWaveVertical:{loadingwavevertical}");
}
tooltipComponent.SetTip(control, tooltipText.ToString());
}
// 递归遍历子控件
if (control.HasChildren)
{
BindButtonWithToolTip(control);
}
}
}
}
}