* UIForm: 增加了查找页面的方法
This commit is contained in:
parent
6055450e7e
commit
188151b58a
Binary file not shown.
Binary file not shown.
@ -88,6 +88,14 @@ namespace Sunny.UI.Demo
|
||||
|
||||
Text = Version + " Build " + Properties.Resources.BuildDate;
|
||||
RegisterHotKey(UI.ModifierKeys.Shift, Keys.F8);
|
||||
|
||||
//根据页面类型获取页面
|
||||
FButton page = GetPage<FButton>();
|
||||
page?.Text.WriteConsole();
|
||||
|
||||
//根据页面索引获取页面
|
||||
UIPage page1 = GetPage(1002);
|
||||
page1?.Text.WriteConsole();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
//新建一个窗体,改继承Form为UIForm
|
||||
//窗体上只要放一个UITabControl,并关联到UIForm,这样多页面框架就已经打好了,其余的可以自由发挥
|
||||
MainTabControl = uiTabControl1;
|
||||
//窗体上如果只有一个UITabControl,也会自动关联,超过一个需要手动关联
|
||||
//MainTabControl = uiTabControl1;
|
||||
|
||||
//有三个UIPage,分别为:
|
||||
//FPage1,其属性PageIndex为1001
|
||||
@ -17,7 +18,7 @@
|
||||
|
||||
//设置FTitlePage1为主页面,不能被关闭
|
||||
var mainPage = new FPage1();
|
||||
MainTabControl.MainPage = mainPage.Text = "主页";
|
||||
uiTabControl1.MainPage = mainPage.Text = "主页";
|
||||
AddPage(mainPage);
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,11 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
public static class ControlEx
|
||||
{
|
||||
public static void ReStart(this Timer timer)
|
||||
public static Timer ReStart(this Timer timer)
|
||||
{
|
||||
timer.Stop();
|
||||
timer.Start();
|
||||
return timer;
|
||||
}
|
||||
|
||||
public static Rectangle ScreenRectangle(this Control ctrl)
|
||||
@ -63,6 +64,27 @@ namespace Sunny.UI
|
||||
return ctrl as Form;
|
||||
}
|
||||
|
||||
public static Control SettingToCenter(this Control ctrl)
|
||||
{
|
||||
return ctrl.SettingToXCenter().SettingToYCenter();
|
||||
}
|
||||
|
||||
public static Control SettingToXCenter(this Control ctrl)
|
||||
{
|
||||
if (ctrl != null && ctrl.Parent != null)
|
||||
ctrl.Left = (ctrl.Parent.Width - ctrl.Width) / 2;
|
||||
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
public static Control SettingToYCenter(this Control ctrl)
|
||||
{
|
||||
if (ctrl != null && ctrl.Parent != null)
|
||||
ctrl.Top = (ctrl.Parent.Height - ctrl.Height) / 2;
|
||||
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
public static Form GetParentForm(this Control ctrl)
|
||||
{
|
||||
while (!IsForm(ctrl.Parent))
|
||||
@ -124,15 +146,17 @@ namespace Sunny.UI
|
||||
return pt;
|
||||
}
|
||||
|
||||
public static void ShowContextMenuStrip(this Control ctrl, ContextMenuStrip menu, Point offset)
|
||||
public static ContextMenuStrip ShowContextMenuStrip(this Control ctrl, ContextMenuStrip menu, Point offset)
|
||||
{
|
||||
//设置显示的位置为鼠标所在的位置
|
||||
menu.Show(ctrl, offset);
|
||||
return menu;
|
||||
}
|
||||
|
||||
public static void ShowContextMenuStrip(this Control ctrl, ContextMenuStrip menu, int offsetX, int offsetY)
|
||||
public static ContextMenuStrip ShowContextMenuStrip(this Control ctrl, ContextMenuStrip menu, int offsetX, int offsetY)
|
||||
{
|
||||
menu.Show(ctrl, offsetX, offsetY);
|
||||
return menu;
|
||||
}
|
||||
|
||||
//https://www.codeproject.com/Tips/1264882/Extension-Methods-for-Multiple-Control-Tags
|
||||
|
@ -783,5 +783,10 @@ namespace Sunny.UI
|
||||
column.SortMode = sortMode;
|
||||
return column;
|
||||
}
|
||||
|
||||
public static bool IsDBNull(this DataGridViewCell cell)
|
||||
{
|
||||
return cell.Value is DBNull;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@ -379,6 +380,32 @@ namespace Sunny.UI
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetPage<T>() where T : UIPage
|
||||
{
|
||||
List<T> result = GetPages<T>();
|
||||
return result.Count > 0 ? result[0] : null;
|
||||
}
|
||||
|
||||
public List<T> GetPages<T>() where T : UIPage
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
foreach (var item in PageItems)
|
||||
{
|
||||
if (item.Key != null)
|
||||
{
|
||||
var tabPage = item.Key;
|
||||
var pages = tabPage.GetControls<UIPage>();
|
||||
for (int i = 0; i < pages.Count; i++)
|
||||
{
|
||||
if (pages[i] is T pg)
|
||||
result.Add(pg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public UIPage GetPage(Guid guid)
|
||||
{
|
||||
if (guid == Guid.Empty) return null;
|
||||
|
@ -223,6 +223,10 @@ namespace Sunny.UI
|
||||
|
||||
public void AddPage(Guid guid, UITabControlMenu page) => Helper.AddPage(guid, page);
|
||||
|
||||
public T GetPage<T>() where T : UIPage => Helper.GetPage<T>();
|
||||
|
||||
public List<T> GetPages<T>() where T : UIPage => Helper.GetPages<T>();
|
||||
|
||||
public string Version
|
||||
{
|
||||
get;
|
||||
|
@ -30,6 +30,7 @@
|
||||
* 2022-01-03: V3.0.9 标题栏按钮可以设置颜色
|
||||
* 2022-02-09: V3.1.0 增加页面间传值方法SetParamToPage
|
||||
* 2022-03-19: V3.1.1 重构主题配色
|
||||
* 2022-03-28: V3.1.1 增加了查找页面的方法
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -1978,57 +1979,44 @@ namespace Sunny.UI
|
||||
|
||||
public UIPage AddPage(UIPage page)
|
||||
{
|
||||
SetDefaultTabControl();
|
||||
page.Frame = this;
|
||||
MainTabControl?.AddPage(page);
|
||||
return page;
|
||||
}
|
||||
|
||||
public virtual void SelectPage(int pageIndex)
|
||||
private UIForm SetDefaultTabControl()
|
||||
{
|
||||
MainTabControl?.SelectPage(pageIndex);
|
||||
if (MainTabControl == null)
|
||||
{
|
||||
List<UITabControl> ctrls = this.GetControls<UITabControl>();
|
||||
if (ctrls.Count == 1) MainTabControl = ctrls[0];
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual void SelectPage(Guid guid)
|
||||
{
|
||||
MainTabControl?.SelectPage(guid);
|
||||
}
|
||||
public virtual void SelectPage(int pageIndex) => SetDefaultTabControl().MainTabControl?.SelectPage(pageIndex);
|
||||
|
||||
public bool RemovePage(int pageIndex)
|
||||
{
|
||||
return MainTabControl?.RemovePage(pageIndex) ?? false;
|
||||
}
|
||||
public virtual void SelectPage(Guid guid) => SetDefaultTabControl().MainTabControl?.SelectPage(guid);
|
||||
|
||||
public bool RemovePage(Guid guid)
|
||||
{
|
||||
return MainTabControl?.RemovePage(guid) ?? false;
|
||||
}
|
||||
public bool RemovePage(int pageIndex) => MainTabControl?.RemovePage(pageIndex) ?? false;
|
||||
|
||||
public virtual void FeedbackFormPage(int fromPageIndex, params object[] objects)
|
||||
{
|
||||
}
|
||||
public bool RemovePage(Guid guid) => MainTabControl?.RemovePage(guid) ?? false;
|
||||
|
||||
public UIPage GetPage(int pageIndex)
|
||||
{
|
||||
return MainTabControl?.GetPage(pageIndex);
|
||||
}
|
||||
public virtual void FeedbackFormPage(int fromPageIndex, params object[] objects) { }
|
||||
|
||||
public UIPage GetPage(Guid guid)
|
||||
{
|
||||
return MainTabControl?.GetPage(guid);
|
||||
}
|
||||
public UIPage GetPage(int pageIndex) => SetDefaultTabControl().MainTabControl?.GetPage(pageIndex);
|
||||
|
||||
public bool ExistPage(int pageIndex)
|
||||
{
|
||||
return GetPage(pageIndex) != null;
|
||||
}
|
||||
public UIPage GetPage(Guid guid) => SetDefaultTabControl().MainTabControl?.GetPage(guid);
|
||||
|
||||
public bool ExistPage(Guid guid)
|
||||
{
|
||||
return GetPage(guid) != null;
|
||||
}
|
||||
public bool ExistPage(int pageIndex) => GetPage(pageIndex) != null;
|
||||
|
||||
public bool ExistPage(Guid guid) => GetPage(guid) != null;
|
||||
|
||||
public bool SetParamToPage(int toPageIndex, int fromPageIndex, params object[] objects)
|
||||
{
|
||||
SetDefaultTabControl();
|
||||
UIPage page = GetPage(toPageIndex);
|
||||
if (page == null) return false;
|
||||
return page.SetParam(fromPageIndex, objects);
|
||||
@ -2036,11 +2024,16 @@ namespace Sunny.UI
|
||||
|
||||
public bool SetParamToPage(Guid toPageGuid, Guid fromPageGuid, params object[] objects)
|
||||
{
|
||||
SetDefaultTabControl();
|
||||
UIPage page = GetPage(toPageGuid);
|
||||
if (page == null) return false;
|
||||
return page.SetParam(fromPageGuid, objects);
|
||||
}
|
||||
|
||||
public T GetPage<T>() where T : UIPage => SetDefaultTabControl().MainTabControl?.GetPage<T>();
|
||||
|
||||
public List<T> GetPages<T>() where T : UIPage => SetDefaultTabControl().MainTabControl?.GetPages<T>();
|
||||
|
||||
#endregion IFrame实现
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user