189 lines
8.5 KiB
C#
Raw Normal View History

using System;
2023-03-26 12:58:28 +08:00
using System.Diagnostics;
using System.Drawing;
2020-05-11 21:11:29 +08:00
using System.Windows.Forms;
namespace Sunny.UI.Demo
{
2024-02-28 20:35:57 +08:00
public partial class FMain : UIForm2
2020-05-11 21:11:29 +08:00
{
public FMain()
{
InitializeComponent();
2023-03-26 12:58:28 +08:00
2020-05-11 21:11:29 +08:00
int pageIndex = 1000;
2023-03-26 12:58:28 +08:00
//uiNavBar1设置节点也可以在Nodes属性里配置
uiNavBar1.Nodes.Add("控件");
uiNavBar1.Nodes.Add("窗体");
uiNavBar1.Nodes.Add("图表");
uiNavBar1.Nodes.Add("工控");
uiNavBar1.Nodes.Add("主题");
uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[0], pageIndex);
uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[0], 61451);
TreeNode parent = uiNavMenu1.CreateNode("控件", 61451, 24, pageIndex);
2021-08-11 23:13:24 +08:00
//通过设置PageIndex关联节点文字、图标由相应的Page的Text、Symbol提供
2023-03-26 12:58:28 +08:00
uiNavMenu1.CreateChildNode(parent, AddPage(new FAvatar(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FButton(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FCheckBox(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FCombobox(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FContextMenuStrip(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FDataGridView(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FFlowLayoutPanel(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FHeaderButton(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FLabel(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FLine(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FListBox(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FNavigation(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FPanel(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FProcess(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FRadioButton(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FScrollBar(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FSplitContainer(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FTabControl(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FTextBox(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FTransfer(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FTreeView(), ++pageIndex));
uiNavMenu1.CreateChildNode(parent, AddPage(new FOther(), ++pageIndex));
2021-08-11 23:13:24 +08:00
//示例设置某个节点的小红点提示
2023-03-26 12:58:28 +08:00
uiNavMenu1.ShowTips = true;
uiNavMenu1.SetNodeTipsText(uiNavMenu1.Nodes[0], "6", Color.Red, Color.White);
uiNavMenu1.SetNodeTipsText(parent.Nodes[1], " ", Color.Lime, Color.White);
2020-05-11 21:11:29 +08:00
pageIndex = 2000;
2023-03-26 12:58:28 +08:00
uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[1], pageIndex);
uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[1], 61818);
parent = uiNavMenu1.CreateNode("窗体", 61818, 24, pageIndex);
//通过设置GUID关联节点字体图标和大小由UIPage设置
2023-03-26 12:58:28 +08:00
uiNavMenu1.CreateChildNode(parent, AddPage(new FDialogs(), Guid.NewGuid()));
uiNavMenu1.CreateChildNode(parent, AddPage(new FEditor(), Guid.NewGuid()));
uiNavMenu1.CreateChildNode(parent, AddPage(new FFrames(), Guid.NewGuid()));
2020-05-11 21:11:29 +08:00
pageIndex = 3000;
2023-03-26 12:58:28 +08:00
uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[2], pageIndex);
uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[2], 61950);
parent = uiNavMenu1.CreateNode("图表", 61950, 24, pageIndex);
//直接关联默认自动生成GUID
2023-03-26 12:58:28 +08:00
uiNavMenu1.CreateChildNode(parent, AddPage(new FBarChart()));
uiNavMenu1.CreateChildNode(parent, AddPage(new FDoughnutChart()));
uiNavMenu1.CreateChildNode(parent, AddPage(new FLineChart()));
uiNavMenu1.CreateChildNode(parent, AddPage(new FPieChart()));
2021-08-11 23:13:24 +08:00
pageIndex = 4000;
2023-03-26 12:58:28 +08:00
uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[3], pageIndex);
uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[3], 362614);
parent = uiNavMenu1.CreateNode("工控", 362614, 24, pageIndex);
2021-08-11 23:13:24 +08:00
//直接关联默认自动生成GUID
2023-03-26 12:58:28 +08:00
uiNavMenu1.CreateChildNode(parent, AddPage(CreateInstance<UIPage>("Sunny.UI.Demo.FPipe")));
uiNavMenu1.CreateChildNode(parent, AddPage(CreateInstance<UIPage>("Sunny.UI.Demo.FMeter")));
uiNavMenu1.CreateChildNode(parent, AddPage(CreateInstance<UIPage>("Sunny.UI.Demo.FLed")));
uiNavMenu1.CreateChildNode(parent, AddPage(CreateInstance<UIPage>("Sunny.UI.Demo.FLight")));
2023-07-09 23:26:30 +08:00
uiNavMenu1.CreateChildNode(parent, AddPage(CreateInstance<UIPage>("Sunny.UI.Demo.FSwitch")));
2023-03-26 12:58:28 +08:00
uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[4], 61502);
2020-05-11 21:11:29 +08:00
var styles = UIStyles.PopularStyles();
foreach (UIStyle style in styles)
{
2023-03-26 12:58:28 +08:00
uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], style.DisplayText(), style.Value());
2020-05-11 21:11:29 +08:00
}
2023-12-08 20:45:53 +08:00
var node = uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], "字体图标", 99999);
uiNavBar1.SetNodeSymbol(node, 558426);
node = uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], "多彩主题", UIStyle.Colorful.Value());
2023-10-27 14:44:49 +08:00
uiNavBar1.SetNodeSymbol(node, 558295);
2023-05-29 22:58:53 +08:00
//左侧导航主节点关联页面
2023-12-08 20:45:53 +08:00
uiNavMenu1.CreateNode(AddPage(new FSymbols()));
2023-05-29 22:58:53 +08:00
uiNavMenu1.CreateNode(AddPage(new FColorful()));
2021-08-11 23:13:24 +08:00
//直接增加一个页面,不在左侧列表显示
2023-05-29 22:58:53 +08:00
//AddPage(new FColorful());
AddPage(new FCommon());
2021-08-11 23:13:24 +08:00
//选中第一个节点
2023-03-26 12:58:28 +08:00
uiNavMenu1.SelectPage(1002);
2023-07-09 23:26:30 +08:00
uiPanel2.Text = Text = Version;
2022-01-19 10:33:20 +08:00
RegisterHotKey(UI.ModifierKeys.Shift, Keys.F8);
//根据页面类型获取页面
FButton page = GetPage<FButton>();
if (page != null)
page.Text.WriteConsole();
//根据页面索引获取页面
UIPage page1 = GetPage(1002);
if (page1 != null)
page1.Text.WriteConsole();
2023-07-09 23:26:30 +08:00
timer1.Start();
2020-05-11 21:11:29 +08:00
}
/// <summary>
/// 创建对象实例
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="fullName">命名空间.类型名</param>
/// <returns></returns>
public static T CreateInstance<T>(string fullName)
{
Type o = Type.GetType(fullName);
dynamic obj = Activator.CreateInstance(o, true);
return (T)obj;//类型转换并返回
}
2023-03-26 12:58:28 +08:00
private void uiNavBar1_MenuItemClick(string itemText, int menuIndex, int pageIndex)
2020-05-11 21:11:29 +08:00
{
switch (menuIndex)
{
2021-08-11 23:13:24 +08:00
case 4:
2020-05-11 21:11:29 +08:00
UIStyle style = (UIStyle)pageIndex;
2023-12-08 20:45:53 +08:00
if (pageIndex < UIStyle.Colorful.Value())
StyleManager.Style = style;
else
2023-05-29 22:58:53 +08:00
uiNavMenu1.SelectPage(pageIndex);
2020-05-11 21:11:29 +08:00
break;
2021-08-11 23:13:24 +08:00
default:
2023-03-26 12:58:28 +08:00
uiNavMenu1.SelectPage(pageIndex);
2021-08-11 23:13:24 +08:00
break;
2020-05-11 21:11:29 +08:00
}
}
2023-03-26 12:58:28 +08:00
private void Form1_PageSelected(object sender, UIPageEventArgs e)
{
2023-03-26 12:58:28 +08:00
if (e.Page != null)
Console.WriteLine(e.Page.Text);
}
2021-02-04 20:49:30 +08:00
private void ToolStripMenuItem1_Click(object sender, EventArgs e)
{
2021-05-20 14:54:51 +08:00
UIMessageBox.Show(Version, "关于", Style, UIMessageBoxButtons.OK, false);
2021-02-04 20:49:30 +08:00
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
2023-03-26 12:58:28 +08:00
Process.Start("https://gitee.com/yhuse/SunnyUI");
2021-02-04 20:49:30 +08:00
}
2022-01-19 10:33:20 +08:00
2023-03-26 12:58:28 +08:00
private void Form1_HotKeyEventHandler(object sender, HotKeyEventArgs e)
2022-01-19 10:33:20 +08:00
{
if (e.hotKey.ModifierKey == UI.ModifierKeys.Shift && e.hotKey.Key == Keys.F8)
{
2024-05-02 23:04:38 +08:00
this.ShowInfoTip("您按下了全局系统热键 Shift+F8");
2022-01-19 10:33:20 +08:00
}
}
2022-09-11 16:10:32 +08:00
2023-03-26 12:58:28 +08:00
private void Form1_ReceiveParams(object sender, UIPageParamsArgs e)
2022-09-11 16:10:32 +08:00
{
Text = e.Value.ToString();
SendParamToPage(1001, "传值给页面");
}
2023-07-09 23:26:30 +08:00
private void timer1_Tick(object sender, EventArgs e)
{
uiPanel3.Text = DateTime.Now.DateTimeString();
}
2020-05-11 21:11:29 +08:00
}
2023-03-26 12:58:28 +08:00
}