258 lines
9.1 KiB
C#
258 lines
9.1 KiB
C#
|
|
using MGdu.WinFormUI;
|
|||
|
|
using MyDb;
|
|||
|
|
using Newtonsoft.Json.Linq;
|
|||
|
|
using ryControls;
|
|||
|
|
using ryControls.Pram;
|
|||
|
|
using SkinPreview;
|
|||
|
|
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
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 无参数启动
|
|||
|
|
/// </summary>
|
|||
|
|
public SKinForm() : base()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
private IntPtr ActiveHandle = IntPtr.Zero;
|
|||
|
|
protected override void OnCreateControl()
|
|||
|
|
{
|
|||
|
|
//ActiveHandle= ryCommon.RyForm.GetActiveWindow();
|
|||
|
|
base.OnCreateControl();
|
|||
|
|
if (!this.DesignMode)
|
|||
|
|
{
|
|||
|
|
InitForm();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
protected override void OnHandleCreated(EventArgs e)
|
|||
|
|
{
|
|||
|
|
ActiveHandle = ryCommon.RyForm.GetActiveWindow();
|
|||
|
|
base.OnHandleCreated(e);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 以参数方式启动
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="args"></param>
|
|||
|
|
public SKinForm(string[] args) : base()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 以单参数方式启动
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="arg"></param>
|
|||
|
|
public SKinForm(string arg) : base()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 窗口打开时间
|
|||
|
|
/// </summary>
|
|||
|
|
public DateTime OpenTime { get; private set; } = DateTime.MinValue;
|
|||
|
|
/// <summary>
|
|||
|
|
/// 是否记录使用情况
|
|||
|
|
/// </summary>
|
|||
|
|
[Description("是否记录使用情况")]
|
|||
|
|
public bool RecordUseTime { get; set; } = true;
|
|||
|
|
/// <summary>
|
|||
|
|
/// 接收到参数
|
|||
|
|
/// </summary>
|
|||
|
|
public static int MSG_RevPram { get; } = 112233;
|
|||
|
|
private void InitForm()
|
|||
|
|
{
|
|||
|
|
OpenTime = DateTime.Now;
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示在父窗体中间,如果没有父窗体,则显示在显示器中间
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="parent"></param>
|
|||
|
|
public void ShowInCenter(Form parent)
|
|||
|
|
{
|
|||
|
|
ShowInCenter(this,parent);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示在父窗体中间,如果没有父窗体,则显示在显示器中间
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="CurForm"></param>
|
|||
|
|
/// <param name="parent"></param>
|
|||
|
|
public static void ShowInCenter(Form CurForm, Form parent)
|
|||
|
|
{
|
|||
|
|
CurForm.WindowState = FormWindowState.Normal;
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
if (parent.WindowState== FormWindowState.Minimized || !parent.Visible) //如果父窗体处于最小化,或者父窗体不可见
|
|||
|
|
{
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
if (x < 0) { x = 0; }
|
|||
|
|
if (y < 0) { y = 0; }
|
|||
|
|
CurForm.Location = new Point(x, y);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 激活窗体
|
|||
|
|
/// </summary>
|
|||
|
|
public void ActiveSkinForm()
|
|||
|
|
{
|
|||
|
|
ryCommon.RyForm.BringToTop(Handle);
|
|||
|
|
ryCommon.RyForm.SetActiveWindow(Handle);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示窗体
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">指定要显示的窗体类型名</param>
|
|||
|
|
public static void ShowForm(Type type)
|
|||
|
|
{
|
|||
|
|
RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type);
|
|||
|
|
form.Show();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示窗体
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">指定要显示的窗体类型名</param>
|
|||
|
|
/// <param name="arg">参数</param>
|
|||
|
|
public static void ShowForm(Type type, string arg)
|
|||
|
|
{
|
|||
|
|
RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type, new object[] { arg });
|
|||
|
|
form.Show();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示窗体
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">指定要显示的窗体类型名</param>
|
|||
|
|
/// <param name="arg">参数</param>
|
|||
|
|
public static void ShowForm(Type type, string[] arg)
|
|||
|
|
{
|
|||
|
|
RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type, arg);
|
|||
|
|
form.Show();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示模式窗体
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">指定要显示的窗体类型名</param>
|
|||
|
|
/// <param name="arg">参数</param>
|
|||
|
|
public static void ShowDialogForm(Type type, string[] arg)
|
|||
|
|
{
|
|||
|
|
RySkins.SKinForm form = (RySkins.SKinForm)Activator.CreateInstance(type, arg);
|
|||
|
|
form.ShowDialog();
|
|||
|
|
form.Dispose();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示窗体,如果当前已经显示过,则激活窗体。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">指定要显示的窗体类型名</param>
|
|||
|
|
public static void ShowFormOne(Form parent, Type type)
|
|||
|
|
{
|
|||
|
|
ShowFormOne(parent,type,null);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示窗体,如果当前已经显示过,则激活窗体。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">指定要显示的窗体类型名</param>
|
|||
|
|
/// <param name="arg">参数</param>
|
|||
|
|
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)
|
|||
|
|
{
|
|||
|
|
JObject jo = new JObject();
|
|||
|
|
for (int j = 0; j < arg.Length; j++)
|
|||
|
|
{
|
|||
|
|
jo.Add("arg_"+j.ToString(), arg[j]);
|
|||
|
|
}
|
|||
|
|
//窗口已存在,发送消息来传送数据
|
|||
|
|
RyWin32.SendMsg(parent.Handle, forms[i].Handle, MSG_RevPram, jo.ToString());
|
|||
|
|
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
|
|||
|
|
{
|
|||
|
|
RySkins.SKinForm.ShowInCenter(forms[i],parent);
|
|||
|
|
forms[i].Show();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
Form form;
|
|||
|
|
if (arg == null)
|
|||
|
|
{ form = (Form)Activator.CreateInstance(type); }
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
form = (Form)Activator.CreateInstance(type, new object[] {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 = SkinSetting.FormSkin; }
|
|||
|
|
//Opacity = 0.97;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SKinForm_FormClosed(object sender, FormClosedEventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|