RaUI/Source/Itrycn_Project2/SkinForms/SkinMdiForm.cs
zilinsoft 11a117a46d ## 📅2025-06-27 星期五更新
### RaUI    V4.0.2506.2701
- *.[新增]RediskCheck类新增支持对.NET3.5和.NET6-.NET9安装状态的判断。
- *.[新增]RyImage类的LoadPic方法新增Timeout参数设置。
- *.[新增]ChromeTabControl控件新增OnTabAddButtonClick和OnTabCloseButtonClick事件。
- *.[新增]Strings类新增GetEngOrNumPos方法,获取字符串里的英文或数字。
- *.[改进]ChromeTabControl默认风格改进。
- *.[改进]GetTimeStr新增ShowSeconds参数。
- *.[改进]RyImage.LoadPic获取网络图片时,UA改为Edge的UA。
- *.[改进]ListBoxEx从内部控件改为公开控件。
- *.[修复]AddHosts(string list,bool write)函数write为false时,不再写入hosts。
- *.[修复]修复无法在属性界面修改RichTextBox2的WordWrap属性的BUG。
- *.[修复]修复ApkOp读取apk内部版本号时,如果版本号带数字0可能无法读取的BUG。
- *.[修复]修复GetVerByVerStr传入null值会报错的BUG。
- *.[修复]修复ComboBoxEx2控件修改SelectedItem和SelectedIndex属性不会激发SelectedIndexChanged事件的BUG。
- *.[修复]修复ApkOp解压某些apk文件时,可能导致文件被占用的BUG。
- *.[修复]修复TextBoxEx2控件通过代码设置文本,无法触发文本变化事件的BUG。
- *.[修复]修复TextBoxEx2控件使用Tab按键,无法切换输入的BUG。
2025-06-27 10:17:58 +08:00

257 lines
9.8 KiB
C#

using MGdu.WinFormUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace RySkins
{
public partial class SkinMdiForm : GMForm
{
/// <summary>
/// 顶部栏
/// </summary>
[Description("顶部栏")]
public Panel TopPanel { get; set; } = null;
/// <summary>
/// 左侧栏
/// </summary>
[Description("左侧栏")]
public Panel LeftPanel { get; set; } = null;
public SkinMdiForm()
{
InitializeComponent();
InitMdiSkin();
}
public SkinMdiForm(string[] args)
{
InitializeComponent();
InitMdiSkin();
}
#region
/// <summary>
/// 加载皮肤
/// </summary>
public void InitMdiSkin()
{
_mdiClient = FindMdiClient();
base.SizeChanged += new EventHandler((object sender, EventArgs e) =>
{
if (base.WindowState == FormWindowState.Maximized)
{
base.ControlBoxOffset = new Point(4, base.BorderWidth);
}
else
{
base.ControlBoxOffset = new Point(4, 1);
}
SetFormItemLocation(TopPanel);
});
base.Load += new EventHandler((object sender, EventArgs e) =>
{
base.XTheme = new RySkins.ThemeForm();
base.XTheme.Mdi_TabMinWidth = 70;
base.XTheme.Mdi_TabNormalWidth = 100;
base.XTheme.Mdi_TabMaxWidth = 145;
base.XTheme.Mdi_ShowNewTabBtn = false;
base.XTheme.Mdi_AlwaysShowListAllBtn = false;
base.XTheme.Mdi_BarBottomRegionHeight = 0;
base.XTheme.Mdi_ShowTabCloseIcon = true;
base.XTheme.Mdi_TabShowBorder = false;
base.XTheme.Mdi_BarMargin = new Padding(6, 0, 100, 0);
base.XTheme.Mdi_TabActiveBackColorTop = Color.White;
base.XTheme.Mdi_ShowTabIcon = false;
base.XTheme.Mdi_TabActiveBackColorBottom = Color.FromArgb(248, 248, 248);
base.XTheme.Mdi_TabDeactiveBackColorTop = Color.FromArgb(230, 230, 230);
base.XTheme.Mdi_TabDeactiveBackColorBottom = Color.FromArgb(230, 230, 230);
//base.XTheme.Mdi_UseMsgToActivateChild
base.MdiNewTabButtonClick += new EventHandler(NewFormClick);
base.MdiTabCloseButtonClick += new EventHandler(ChildFormClose);
//base.XTheme.Mdi_TabTopSpace += 80;
if (_mdiClient != null)
{
_mdiClient.Dock = DockStyle.None;
_mdiClient.BackColor = Color.White;
}
this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - Height) / 2);
});
base.MdiBarCreated += new EventHandler((object sender, EventArgs e) =>
{
SetFormItemLocation(TopPanel);
Application.DoEvents();
Thread th = new Thread(Start);
th.Start();
void Start()
{
Thread.Sleep(10);
this.Invoke(new Action(() =>
{
this.SuspendLayout();
//CreateNewChild(typeof(DYun.OTools.FrmGZ));
for (int i = 0; i < MdiForms.Count; i++)
{
CreateNewChild(MdiForms[i]);
}
this.ResumeLayout(false);
//CreateNewChild(typeof(DbOp.FrmCaijiView));
//Application.DoEvents();
if (this.MdiChildren.Length > 0)
{
this.ActivateMdiChildForm(this.MdiChildren[0]);
}
}));
}
});
}
/// <summary>
/// 要初始化加载的Form列表
/// </summary>
public List<Form> MdiForms { get; set; } = new List<Form>();
/// <summary>
/// 创建子窗体
/// </summary>
/// <param name="form"></param>
public void CreateNewChild(Form form)
{
//form.SuspendLayout();
form.FormClosed += new FormClosedEventHandler(base.MdiChildClosed);
form.VisibleChanged += new EventHandler(base.MdiChildVisibleChange);
form.MdiParent = this;
//f.BackColor = Color.White;
//form.FormBorderStyle = FormBorderStyle.SizableToolWindow;
form.SizeGripStyle = SizeGripStyle.Show;
form.WindowState = FormWindowState.Maximized;
form.Show();
//form.Refresh();
// form.ResumeLayout(false);
//f.Focus();
}
private void CreateNewChild(Type form)
{
Form f = (Form)Activator.CreateInstance(form);
f.FormClosed += new FormClosedEventHandler(base.MdiChildClosed);
f.VisibleChanged += new EventHandler(base.MdiChildVisibleChange);
f.MdiParent = this;
//f.BackColor = Color.White;
f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
f.SizeGripStyle = SizeGripStyle.Show;
f.WindowState = FormWindowState.Maximized;
f.Show();
//f.Focus();
}
MdiClient _mdiClient;
private int PanelTopHeight
{
get
{
return TopPanel == null ? 0 : TopPanel.Height;
}
}
private void NewFormClick(object sender, EventArgs e)
{
// CreateNewChild();
}
/// <summary>
/// 至少保留一个子窗体
/// </summary>
public bool AleastOneChild { get; set; } = true;
private void ChildFormClose(object sender, EventArgs e)
{
if (sender is Form f)
{
if (AleastOneChild)
{
if (this.GetCurrentMdiChildren().Count == 1) { return; }
}
f.Close();
}
this.Invalidate();
}
private MdiClient FindMdiClient()
{
MdiClient mdi = null;
foreach (Control c in Controls)
{
if ((mdi = c as MdiClient) != null)
{
break;
}
}
return mdi;
}
private void SetMdiBarLocation()
{
Padding newMargin = Padding.Empty;
//if (WindowState == FormWindowState.Maximized)
// newMargin = new Padding(BorderWidth, BorderWidth, BorderWidth, 0);
//else
//PnlMenu.Top = BorderWidth + base.XTheme.CaptionHeight;
int left_bar_width = 0;
if (LeftPanel != null) { left_bar_width = LeftPanel.Width; }
newMargin = new Padding(BorderWidth + left_bar_width, BorderWidth + base.XTheme.CaptionHeight + PanelTopHeight, BorderWidth, 0);
if (base.XTheme.Mdi_BarMargin != newMargin)
{
base.XTheme.Mdi_BarMargin = newMargin;
Invalidate();
}
}
private void SetPanelTopLocation(Panel PnlTop)
{
//Point newLocation = new Point(base.MdiBarBounds.Left, base.XTheme.CaptionHeight + BorderWidth);
//var size = new Size(base.MdiBarBounds.Width, PanelTopHeight);
//if (PnlTop != null)
//{
// //PnlTop.Anchor = AnchorStyles.None;
// PnlTop.Location = newLocation;
// PnlTop.Size = size;
// //PnlTop.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
//}
}
private void SetFormItemLocation(Panel PnlTop)
{
if (DesignMode) { return; }
SetMdiBarLocation();
SetPanelTopLocation(PnlTop);
SetMdiClientLocation(PnlTop);
}
private void SetMdiClientLocation(Panel PnlTop)
{
if (_mdiClient == null)
return;
int left_bar_width = 0;
if (LeftPanel != null) { left_bar_width = LeftPanel.Width; }
Point newLocation = new Point(BorderWidth, base.XTheme.CaptionHeight + base.XTheme.Mdi_TabHeight);
var size = new Size(ClientRectangle.Width - BorderWidth - BorderWidth, ClientRectangle.Height - base.XTheme.CaptionHeight - base.XTheme.Mdi_TabHeight - BorderWidth);
if (PnlTop != null)
{
newLocation = new Point(PnlTop.Left + left_bar_width, PnlTop.Bottom + base.XTheme.Mdi_TabHeight);
if (_mdiClient.Location == newLocation)
return;
int height = base.Height - newLocation.Y - BorderWidth - BorderWidth;
size = new Size(PnlTop.Width - left_bar_width, height);
}
_mdiClient.Anchor = AnchorStyles.None;
_mdiClient.Location = newLocation;
_mdiClient.Size = size;
_mdiClient.Anchor =
AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
}
#endregion
private void SkinMdiForm_Load(object sender, EventArgs e)
{
}
}
}