RaUI/Source/Itrycn_Project2/Public/SkinForms/SKinForm.cs
zilinsoft 7ff45b3074 ## 📅2026-06-04 星期四更新
### RaUI    V4.0.2606.0401
- *.[新增]QuickWeb新增支持重试次数。
- *.[新增]RySetting类新增支持json格式设置存储和获取。
- *.[新增]RySetting类新增支持读取设置到内存,然后按配置名称读取。
- *.[新增]新增SuperFileSearch类,文件查找。
- *.[新增]QuickWeb新增CurPageUrl属性。
- *.[新增]HardWare新增支持获取显示器信息。
- *.[新增]HardWare新增GetWMI函数。
- *.[改进]QuickWeb类的UA从IE改为Edge。
- *.[改进]Hosts类IP与域名分隔符从\t改为三个空格。
- *.[改进]RyImage的CropOrFill函数,如果输入的长宽比例与原图一致,则返回原图的副本而不是原图。
- *.[改进]RySoft类的CompareVer函数支持特殊格式的版本号。
- *.[改进]QuickWeb的ConvertUrl函数新增支持自动从CurPageUrl获取。
- *.[改进]DateDiff函数对时间差异小于等于10秒的,自动加上毫秒数据。
- *.[修复]修复ObjectListView控件的AspectGetter方法可能调用null对象的问题。
- *.[修复]修复日期选择控件在获取节假日数据时,会因为节假日文件夹无法访问而报错的问题。
- *.[修复]修复某些情况下剪切板权限问题导致ObjectListView控件报错。
- *.[修复]修复RyImage的CropOrFill函数图片比例不一致时,也是返回原图副本的BUG。
### Itrycn_Project2    V1.0.2606.0401
- *.[改进]将公共调用,无需新增内容的部分代码,改到Public文件夹下
2026-06-04 09:40:37 +08:00

214 lines
7.4 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.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();
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();
}
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);
}
}
}
/// <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.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);
}
/// <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)
{
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;
}
}
}