using MGdu.WinFormUI; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace RySkins { [ComVisible(true)] public partial class SKinForm : GMForm { /// /// 无参数启动 /// public SKinForm() : base() { InitializeComponent(); } private IntPtr ActiveHandle = IntPtr.Zero; protected override void OnCreateControl() { //ActiveHandle= ryCommon.RyForm.GetActiveWindow(); base.OnCreateControl(); InitForm(); } protected override void OnHandleCreated(EventArgs e) { ActiveHandle = ryCommon.RyForm.GetActiveWindow(); base.OnHandleCreated(e); } /// /// 以参数方式启动 /// /// public SKinForm(string[] args) : base() { InitializeComponent(); } /// /// 以单参数方式启动 /// /// public SKinForm(string arg) : base() { InitializeComponent(); } private void InitForm() { if (this.Parent == null) { if (this.StartPosition == FormStartPosition.CenterParent) { var handle = ActiveHandle; var parent_handle = WinAPI.User32.GetParent(Handle); //var dd= this.ParentForm; if (parent_handle == IntPtr.Zero) { parent_handle = handle; } var forms = Application.OpenForms; for (int i = 0; i < forms.Count; i++) { if (forms[i].Handle == handle) { ShowInCenter(forms[i]); break; } } } else if (this.StartPosition == FormStartPosition.CenterScreen) { ShowInCenter(null); } } } /// /// 显示在父窗体中间,如果没有父窗体,则显示在显示器中间 /// /// public void ShowInCenter(Form parent) { ShowInCenter(this, parent); } /// /// 显示在父窗体中间,如果没有父窗体,则显示在显示器中间 /// /// /// public static void ShowInCenter(Form CurForm, Form parent) { CurForm.StartPosition = FormStartPosition.Manual; var screen = Screen.FromControl(CurForm); if (parent == null) //如果没有父窗体,则显示在显示器中间 { CurForm.Location = new Point((screen.WorkingArea.Width - CurForm.Width) / 2, (screen.WorkingArea.Height - CurForm.Height) / 2); return; } var x = parent.Left + (parent.Width - CurForm.Width) / 2; var y = parent.Top + (parent.Height - CurForm.Height) / 2; if ((x + CurForm.Width) > screen.WorkingArea.X + screen.WorkingArea.Width) { x = screen.WorkingArea.X + screen.WorkingArea.Width - CurForm.Width; } if ((y + CurForm.Height) > screen.WorkingArea.Y + screen.WorkingArea.Height) { y = screen.WorkingArea.Y + screen.WorkingArea.Height - CurForm.Height; } CurForm.Location = new Point(x, y); } /// /// 激活窗体 /// public void ActiveSkinForm() { ryCommon.RyForm.BringToTop(Handle); ryCommon.RyForm.SetActiveWindow(Handle); } /// /// 显示窗体 /// /// 指定要显示的窗体类型名 public static void ShowForm(Type type) { RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type); form.Show(); } /// /// 显示窗体 /// /// 指定要显示的窗体类型名 /// 参数 public static void ShowForm(Type type, string arg) { RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type, new object[] { arg }); form.Show(); } /// /// 显示窗体 /// /// 指定要显示的窗体类型名 /// 参数 public static void ShowForm(Type type, string[] arg) { RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type, arg); form.Show(); } /// /// 显示模式窗体 /// /// 指定要显示的窗体类型名 /// 参数 public static void ShowDialogForm(Type type, string[] arg) { RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type, arg); form.ShowDialog(); form.Dispose(); } /// /// 显示窗体,如果当前已经显示过,则激活窗体。 /// /// 指定要显示的窗体类型名 public static void ShowFormOne(Form parent, Type type) { ShowFormOne(parent, type, null); } /// /// 显示窗体,如果当前已经显示过,则激活窗体。 /// /// 指定要显示的窗体类型名 /// 参数 public static void ShowFormOne(Form parent, Type type, string[] arg) { var forms = Application.OpenForms; for (int i = 0; i < forms.Count; i++) { if (forms[i].GetType() == type) { if (forms[i] is RySkins.SKinForm) { var skin_form = (RySkins.SKinForm)forms[i]; skin_form.ShowInCenter(parent); skin_form.ActiveSkinForm(); skin_form.Show(); return; } else { forms[i].Show(); } } } Form form; if (arg == null) { form = (Form)Activator.CreateInstance(type); } else { form = (Form)Activator.CreateInstance(type, arg); } ShowInCenter(form, parent); ryCommon.RyForm.BringToTop(form.Handle); ryCommon.RyForm.SetActiveWindow(form.Handle); form.Show(); } private void SKinForm_Load(object sender, EventArgs e) { if (!this.DesignMode) { base.XTheme = new ThemeForm(); } //Opacity = 0.97; } } }