FrmAbout.cs
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
namespace SmartScan
{
public partial class FrmAbout : Asa.FaceControl.FaceFormFixed
{
private ElementHost wpfHost;
private SmartScan.SetControl.WPF.AboutWindowHost aboutControl;
public FrmAbout()
{
InitializeComponent();
// 设置WinForms窗体的基本属性
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = System.Drawing.Color.FromArgb(18, 18, 18); // 与WPF背景相匹配
this.StartPosition = FormStartPosition.CenterParent;
this.Size = new System.Drawing.Size(490, 342); // 设置与WPF控件相同的尺寸
// 初始化ElementHost
//InitializeWpfControl();
}
private void InitializeWpfControl()
{
// 创建ElementHost控件
wpfHost = new ElementHost();
wpfHost.Dock = DockStyle.Fill;
// 创建WPF用户控件实例
aboutControl = new SmartScan.SetControl.WPF.AboutWindowHost();
RegisterWpfEvents();
// 设置WPF控件的事件处理
// 假设您在WPF控件中公开了一个CloseRequested事件
// aboutControl.CloseRequested += (s, e) => this.Close();
// 将WPF控件分配给ElementHost
wpfHost.Child = aboutControl;
// 将ElementHost添加到WinForms窗体
this.Controls.Add(wpfHost);
}
private void RegisterWpfEvents()
{
// 如果WPF控件提供了关闭和最小化事件,可以在这里注册
// 例如:
aboutControl.CloseRequested += (s, e) => this.Close();
aboutControl.MinimizeRequested += (s, e) => this.WindowState = FormWindowState.Minimized;
aboutControl.VersionTextClicked += AboutControl_VersionTextClicked;
}
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && m.Result.ToInt32() == HTCLIENT)
{
m.Result = (IntPtr)HTCAPTION;
}
}
private void FrmAbout_Load(object sender, EventArgs e)
{
//faceLabel2.Text = BLLCommon.config.SoftVersion;
// 保存版本信息,以便可能需要在WPF控件中使用
string versionInfo = BLLCommon.config.SoftVersion;
// 隐藏所有现有的WinForms控件
HideExistingControls();
// 初始化和显示WPF控件
InitializeWpfControl();
}
private void HideExistingControls()
{
// 遍历当前窗体上的所有控件并隐藏它们
foreach (Control control in this.Controls)
{
// 如果不想隐藏特定控件,可以在这里添加条件判断
control.Visible = false;
}
}
private void AboutControl_VersionTextClicked(object sender, EventArgs e)
{
// 在这里处理版本号点击
// 例如显示高级配置对话框
ConfigHelper.AdvanceConfigForm.ShowEditDialog(this);
}
private void faceLabel2_Click(object sender, EventArgs e)
{
ConfigHelper.AdvanceConfigForm.ShowEditDialog(this);
}
}
}