// Copyright (C) Tom <17379620>. All Rights Reserved.
// AntdUI WinForm Library | Licensed under Apache-2.0 License
// Gitee: https://gitee.com/AntdUI/AntdUI
// GitHub: https://github.com/AntdUI/AntdUI
// GitCode: https://gitcode.com/AntdUI/AntdUI
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace Demo.Controls
{
public partial class ContextMenuStrip : UserControl
{
AntdUI.BaseForm form;
public ContextMenuStrip(AntdUI.BaseForm _form)
{
form = _form;
InitializeComponent();
string svg_back = "", svg_refresh = "", svg_save = "", svg_print = "", svg_laptop = "", svg_qr = "", svg_a = "", svg_fy = "", svg_add = "", svg_share = "", svg_about = "";
menulist = new AntdUI.IContextMenuStripItem[]
{
new AntdUI.ContextMenuStripItem("返回", "Alt+向左键").SetIcon(svg_back),
new AntdUI.ContextMenuStripItem("刷新", "Ctrl+R").SetIcon(svg_refresh),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("另存为", "Ctrl+S").SetIcon(svg_save),
new AntdUI.ContextMenuStripItem("打印", "Ctrl+P").SetIcon(svg_print),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("发送标签页到你的设备").SetIcon(svg_laptop),
new AntdUI.ContextMenuStripItem("为此页面创建QR代码").SetIcon(svg_qr),
new AntdUI.ContextMenuStripItem("大声朗读", "Ctrl+Shift+U").SetIcon(svg_a),
new AntdUI.ContextMenuStripItem("翻译为 中文(简体)").SetIcon(svg_fy),
new AntdUI.ContextMenuStripItem("将页面添加到集锦").SetIcon(svg_add).SetSub(
new AntdUI.ContextMenuStripItem("返回", "Alt+向左键").SetIcon(svg_back).SetSub(
new AntdUI.ContextMenuStripItem("返回", "Alt+向左键").SetIcon(svg_back),
new AntdUI.ContextMenuStripItem("刷新", "Ctrl+R").SetIcon(svg_refresh),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("另存为", "Ctrl+S").SetIcon(svg_save),
new AntdUI.ContextMenuStripItem("打印", "Ctrl+P").SetIcon(svg_print)
),
new AntdUI.ContextMenuStripItem("刷新", "Ctrl+R").SetIcon(svg_refresh),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("另存为", "Ctrl+S").SetIcon(svg_save),
new AntdUI.ContextMenuStripItem("打印", "Ctrl+P").SetIcon(svg_print)
),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("共享").SetIcon(svg_share),
new AntdUI.ContextMenuStripItem("关于").SetIcon(svg_about)
};
}
AntdUI.IContextMenuStripItem[] menulist = { };
private void ContextMenuStrip_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
AntdUI.ContextMenuStrip.open(this, it =>
{
Debug.WriteLine("点击内容:" + it.Text);
AntdUI.Message.info(form, "点击内容:" + it.Text);
}, menulist);
}
}
#region 回调案例
private void Control_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
var config = new AntdUI.ContextMenuStrip.Config(this, RightKey, menulist)
{
Font = new Font("Microsoft YaHei UI", 10f, FontStyle.Bold)
};
AntdUI.ContextMenuStrip.open(config);
}
}
private void RightKey(AntdUI.ContextMenuStripItem it)
{
if (it.Text.Equals("新增"))
{
// 执行对应的操作
}
if (it.Text.Equals("修改"))
{
}
if (it.Text.Equals("删除"))
{
}
if (it.Text.Equals("刷新"))
{
}
if (it.Text.Equals("重置"))
{
}
}
#endregion
private void button1_MouseClick(object sender, MouseEventArgs e)
{
AntdUI.ContextMenuStrip.open(this, it =>
{
Debug.WriteLine("点击内容:" + it.Text);
AntdUI.Message.info(form, "点击内容:" + it.Text);
}, menulist);
}
private void button2_Click(object sender, EventArgs e)
{
button2.StopAnimationBlink();
notifyIcon1.Icon = form.Icon;
notifyIcon1.Visible = !notifyIcon1.Visible;
if (notifyIcon1.Visible) notifyIcon1.ShowBalloonTip(2000, "Hello, Ant Design!", header1.Description, ToolTipIcon.Info);
}
private void notifyIcon1_MouseDown(object sender, MouseEventArgs e)
{
AntdUI.ContextMenuStrip.open(form, notifyIcon1, it =>
{
Debug.WriteLine("托盘点击内容:" + it.Text);
AntdUI.Message.info(form, "托盘点击内容:" + it.Text);
}, menulist);
}
private void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
{
button2.AnimationBlinkTransition(200, AntdUI.Style.Db.Primary, Color.FromArgb(255, 0, 0), Color.FromArgb(255, 128, 0),
Color.FromArgb(255, 255, 0), Color.FromArgb(0, 255, 0), Color.FromArgb(0, 255, 255), Color.FromArgb(0, 0, 255), Color.FromArgb(0, 0, 255));
}
}
}