802 lines
32 KiB
C#
802 lines
32 KiB
C#
/******************************
|
|
* 说明:主界面
|
|
* 创建人:龚宇超
|
|
* 创建日期:2018-04-25
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Lskj.Main.Model;
|
|
using Lskj.Main.Properties;
|
|
using DevExpress.XtraEditors;
|
|
using Lskj.Model;
|
|
using Lskj.Control;
|
|
using Lskj.Data;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Business;
|
|
using Lskj.Util;
|
|
using Lskj.Main.Control;
|
|
using Lskj.Business.Impl;
|
|
using DevExpress.XtraTab;
|
|
using DevExpress.XtraEditors.Controls;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using Lskj.Control.ZKFinger;
|
|
|
|
namespace Lskj.Main
|
|
{
|
|
|
|
/// <summary>
|
|
/// 主界面
|
|
/// </summary>
|
|
public partial class FrmMain : Form
|
|
{
|
|
/// <summary>
|
|
/// 屏幕dpix、dpiy
|
|
/// </summary>
|
|
private float _dpiX, _dpiY;
|
|
/// <summary>
|
|
/// 是否鼠标按下
|
|
/// </summary>
|
|
private bool _isMouseDown;
|
|
/// <summary>
|
|
/// 记录窗口位置
|
|
/// </summary>
|
|
private Point _mousePostion;
|
|
/// <summary>
|
|
/// 语音识别引擎
|
|
/// </summary>
|
|
private SpeechHelp speechHelp = new SpeechHelp();
|
|
/// <summary>
|
|
/// 水印层
|
|
/// </summary>
|
|
private FrmWatermark watermarkForm;
|
|
public FrmMain()
|
|
{
|
|
Graphics graphics = this.CreateGraphics();
|
|
_dpiX = graphics.DpiX;
|
|
_dpiY = graphics.DpiY;
|
|
InitializeComponent();
|
|
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
|
|
|
|
}
|
|
#region 内存回收
|
|
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
|
|
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
|
|
/// <summary>
|
|
/// <para>说明:释放内存</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-09-29 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
public static void ClearMemory()
|
|
{
|
|
GC.Collect();
|
|
GC.WaitForPendingFinalizers();
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
{
|
|
//FrmMian为我窗体的类名
|
|
FrmMain.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
|
|
}
|
|
}
|
|
#endregion
|
|
/// <summary>
|
|
/// <para>说明:窗口加载</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-25 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmMain_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
ERPInfo.Instance.MainControl = this;
|
|
this.Text = SystemInfo.Instance.ClientName + "ERP系统:" + ERPInfo.Instance.UserName;
|
|
this.mainPanelControlEx.Hide();
|
|
//FrmAutoSqlLoad frm = new FrmAutoSqlLoad();
|
|
//frm.ShowDialog();
|
|
this.KeyPreview = true;//主窗体允许使用事件
|
|
this.mainPanelControlEx.DpiX = _dpiX;
|
|
this.mainPanelControlEx.DpiY = _dpiY;
|
|
this.mainPanelControlEx.OnLoad();
|
|
this.mainPanelControlEx.OnCloseButtonCallBack += new EventHandler(OnCloseButtonCallBack);
|
|
this.mainPanelControlEx.OnMaxButtonCallBack += new EventHandler(OnTopPanelMouseDoubleClickCallBack);
|
|
this.mainPanelControlEx.OnMinButtonCallBack += new EventHandler(OnMinButtonCallBack);
|
|
this.mainPanelControlEx.OnTopMouseDownCallback += new MouseEventHandler(OnTopMouseDownCallback);
|
|
this.mainPanelControlEx.OnTopMouseMoveCallBack += new MouseEventHandler(OnTopMouseMoveCallBack);
|
|
this.mainPanelControlEx.OnTopMouseUpCallBack += new MouseEventHandler(OnTopMouseUpCallBack);
|
|
this.mainPanelControlEx.OnTopPanelMouseDoubleClickCallBack += new EventHandler(OnTopPanelMouseDoubleClickCallBack);
|
|
if (SystemInfo.Instance.DetectionMemory)
|
|
{
|
|
this.TheMemoryTest.Start();
|
|
}
|
|
this.mainPanelControlEx.State = this.WindowState;
|
|
this.MouseMove += OnFrmMainMouseMove;
|
|
this.MouseLeave += OnFrmMainMouseLeave;
|
|
|
|
|
|
if (SystemInfo.Instance.DisplayWatermark)
|
|
{
|
|
watermarkForm = new FrmWatermark(this);
|
|
watermarkForm.Size = this.ClientSize; // 设置水印窗体的大小与主窗体客户端区域相同
|
|
watermarkForm.Location = this.PointToScreen(new Point(0, 0)); // 将水印窗体定位到主窗体的位置
|
|
//watermarkForm.TopMost = true; // 确保水印窗体始终位于最顶层
|
|
watermarkForm.Show(this); // 显示水印窗体
|
|
//watermarkForm.StartPosition = FormStartPosition.CenterScreen;//居中显示
|
|
//watermarkForm.Show(this);// 使用Show方法的overload,设置为最上层显示
|
|
this.SizeChanged += FrmMain_SizeChanged;
|
|
//this.LocationChanged += FrmMain_LocationChanged;
|
|
ERPInfo.Instance.WatermarkForm = watermarkForm;
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
this.mainPanelControlEx.Show();
|
|
}
|
|
}
|
|
|
|
private void OnFrmMainMouseLeave(object sender, EventArgs e)
|
|
{
|
|
Cursor = Cursors.Arrow;// 移出窗体变为正常
|
|
}
|
|
|
|
private void OnFrmMainMouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (WindowState == FormWindowState.Maximized)
|
|
{
|
|
return;
|
|
}
|
|
if (e.Button == MouseButtons.Left)//左键按下移动,拖拽调整大小
|
|
{
|
|
// MousePosition的参考点是屏幕的左上角,表示鼠标当前相对于屏幕左上角的坐标。this.Left和this.Top的参考点也是屏幕
|
|
if (Cursor == Cursors.SizeNWSE) // 倾斜拖拽
|
|
{
|
|
// 改变窗体宽和高的代码,其宽高为鼠标屏幕位置减去窗体的Left,Top距离
|
|
this.Width = MousePosition.X - this.Left;
|
|
this.Height = MousePosition.Y - this.Top;
|
|
}
|
|
else if (Cursor == Cursors.SizeWE) // 水平拖拽
|
|
{
|
|
Width = MousePosition.X - this.Left;
|
|
}
|
|
else if (Cursor == Cursors.SizeNS) // 垂直拖拽
|
|
{
|
|
Height = MousePosition.Y - this.Top;
|
|
}
|
|
}
|
|
//鼠标移动过程中,坐标时刻在改变
|
|
//当鼠标移动时横坐标距离窗体右边缘5像素以内且纵坐标距离下边缘也在5像素以内时,要将光标变为倾斜的箭头形状
|
|
if (e.Location.X >= this.Width - 3 && e.Location.Y > this.Height - 3)
|
|
{
|
|
this.Cursor = Cursors.SizeNWSE; // 右下角 双向对角线光标
|
|
}
|
|
//当鼠标移动时横坐标距离窗体右边缘5像素以内时,要将光标变为双向水平箭头形状
|
|
else if (e.Location.X >= this.Width - 3)
|
|
{
|
|
this.Cursor = Cursors.SizeWE; // 双向水平光标
|
|
}
|
|
//当鼠标移动时纵坐标距离窗体下边缘5像素以内时,要将光标变为垂直水平箭头形状
|
|
else if (e.Location.Y >= this.Height - 3)
|
|
{
|
|
this.Cursor = Cursors.SizeNS; // 双向垂直光标
|
|
|
|
}
|
|
//否则,以外的窗体区域,鼠标星座均为单向箭头(默认)
|
|
else this.Cursor = Cursors.Arrow;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 窗体位置改变时,水印层对应改变
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmMain_LocationChanged(object sender, EventArgs e)
|
|
{
|
|
if (!IsWatermarkAvailable()) return;
|
|
|
|
watermarkForm.Size = this.ClientSize; // 设置水印窗体的大小与主窗体客户端区域相同
|
|
watermarkForm.Location = this.PointToScreen(new Point(0, 0)); // 将水印窗体定位到主窗体的位置
|
|
}
|
|
|
|
/// <summary>
|
|
/// 窗体状态改变时,水印层对应改变
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmMain_SizeChanged(object sender, EventArgs e)
|
|
{
|
|
if (SystemInfo.Instance.DisplayWatermark)
|
|
{
|
|
if (!IsWatermarkAvailable()) return;
|
|
|
|
if (ERPInfo.Instance.MainControl.WindowState == FormWindowState.Minimized) watermarkForm.Visible = false;
|
|
|
|
if (ERPInfo.Instance.MainControl.WindowState != FormWindowState.Minimized)
|
|
{
|
|
//watermarkForm.Size = this.ClientSize; // 设置水印窗体的大小与主窗体客户端区域相同
|
|
//watermarkForm.Location = this.PointToScreen(new Point(0, 0)); // 将水印窗体定位到主窗体的位置
|
|
watermarkForm.Visible = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private bool IsWatermarkAvailable()
|
|
{
|
|
return watermarkForm != null && !watermarkForm.IsDisposed && !watermarkForm.Disposing;
|
|
}
|
|
|
|
private void CloseWatermarkForm()
|
|
{
|
|
this.SizeChanged -= FrmMain_SizeChanged;
|
|
|
|
if (IsWatermarkAvailable())
|
|
{
|
|
watermarkForm.SafeClose();
|
|
if (!watermarkForm.IsDisposed)
|
|
{
|
|
watermarkForm.Dispose();
|
|
}
|
|
}
|
|
|
|
watermarkForm = null;
|
|
ERPInfo.Instance.WatermarkForm = null;
|
|
}
|
|
/// <summary>
|
|
/// U盾状态改变
|
|
/// </summary>
|
|
/// <param name="m"></param>
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
base.WndProc(ref m);//调用父类方法,以确保其他功能正常
|
|
switch (m.WParam.ToInt32())
|
|
{
|
|
//U盾改变事件
|
|
case 7:
|
|
if (SystemInfo.Instance.IsDogVerify)
|
|
{
|
|
int[] keyHandles = ERPInfo.Instance.keyHandles = new int[8];
|
|
int[] keyNumber = ERPInfo.Instance.keyNumber = new int[8];
|
|
int rtn = Lskj.Core.SmartX1Api.SmartX1Find("Ls_ERP", keyHandles, keyNumber);
|
|
if (rtn != 0)
|
|
{
|
|
ERPInfo.Instance.isDogVerifyPassword = true;
|
|
int closeCount = 0;
|
|
if (StaticControl.DogVerifyModuleForms.Count > 0)
|
|
{
|
|
foreach (DevExpress.XtraTab.XtraTabPage page in StaticControl.DogVerifyModuleForms)
|
|
{
|
|
this.mainPanelControlEx.TabMain.Invoke(new Action(() =>
|
|
{
|
|
try
|
|
{
|
|
if (this.mainPanelControlEx.TabMain.TabPages.Contains(page))
|
|
{
|
|
this.mainPanelControlEx.TabMain.TabPages.Remove(page);
|
|
page.Dispose();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}));
|
|
closeCount += 1;
|
|
}
|
|
StaticControl.DogVerifyModuleForms.Clear();
|
|
}
|
|
if (StaticControl.DogVerifyNoPageForms.Count > 0)
|
|
{
|
|
foreach (IForm iForm in StaticControl.DogVerifyNoPageForms)
|
|
{
|
|
try
|
|
{
|
|
iForm.SubForm.Invoke(new Action(() =>
|
|
{
|
|
iForm.SubForm.Close();
|
|
iForm.SubForm.Dispose();
|
|
}));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
closeCount += 1;
|
|
}
|
|
StaticControl.DogVerifyNoPageForms.Clear();
|
|
}
|
|
if (closeCount > 0)
|
|
{
|
|
MessageUtil.Show("U盾已断开连接,当前权限模块已关闭");
|
|
}
|
|
}
|
|
}
|
|
if (SystemInfo.Instance.IsFingerLogin)
|
|
{
|
|
if (StaticControl.fingerHelper != null)
|
|
{
|
|
StaticControl.fingerHelper.Close();
|
|
StaticControl.fingerHelper = null;
|
|
}
|
|
FingerHelper.FreeSensor();
|
|
StaticControl.fingerHelper = new FingerHelper();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:通过分辨率界面重绘方法</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2021-11-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnClickKeyboard(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.F3)
|
|
{
|
|
IntPtr hWnd = GetForegroundWindow(); //获取活动窗口句柄
|
|
int calcID = 0; //进程ID pid
|
|
int calcTD = 0; //线程ID
|
|
calcTD = GetWindowThreadProcessId(hWnd, out calcID);
|
|
Clipboard.SetData(DataFormats.Text, (Object)calcID);
|
|
MessageUtil.Show("程序PID码:" + calcID + "已复制到粘贴板上!");
|
|
}
|
|
else if (e.KeyCode == Keys.F4)
|
|
{
|
|
DataRow rowItem = MainImpl.GetDataRowResult(string.Format("select * from p_formmenuconfigtab where menuid='{0}'", SystemInfo.Instance.QuickMenuId));
|
|
if (rowItem != null)
|
|
{
|
|
string[] arr = new string[] { rowItem["DllFileName"] + "", rowItem["PurviewId"] + "", rowItem["MenuId"] + "", rowItem["UrlParams"] + "", rowItem["SubSysId"] + "", rowItem["menucaption"] + "" };
|
|
Manager.OpenModule(arr[2], arr[5], arr[0], arr[1], arr[3]);
|
|
}
|
|
}
|
|
else if (e.Control && e.KeyValue == 192)
|
|
{
|
|
////speechHelp.StartSpeech();
|
|
//Form form = new Form();
|
|
//Lskj.Control.PdfEditorEx pdfEditorEx = new PdfEditorEx();
|
|
//pdfEditorEx.Dock = DockStyle.Fill;
|
|
//form.Controls.Add(pdfEditorEx);
|
|
//form.ShowDialog();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:通过分辨率界面重绘方法</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-08-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
public void AutoLoadSize(System.Windows.Forms.Control Control)
|
|
{
|
|
foreach (System.Windows.Forms.Control C in Control.Controls)
|
|
{
|
|
if (C.Controls.Count > 0)
|
|
{
|
|
AutoLoadSize(C);
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:重置窗口大小</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-27 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void ResetFormState()
|
|
{
|
|
|
|
foreach (string item in Manager.ModuleForms.Keys)
|
|
{
|
|
DllModule module = Manager.ModuleForms[item];
|
|
//(module.ModuleForm as Form).WindowState = FormWindowState.Maximized;
|
|
//(module.ModuleForm as Form).WindowState = this.WindowState;
|
|
////(module.ModuleForm as Form).ModuleForm = DockStyle.Fill;
|
|
//(module.ModuleForm as Form).Width = this.Width - 6;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:关闭窗口</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnCloseButtonCallBack(object sender, EventArgs e)
|
|
{
|
|
CloseWatermarkForm();
|
|
this.Close();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:窗口最大化</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void OnTopPanelMouseDoubleClickCallBack(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.WindowState == FormWindowState.Normal)
|
|
{
|
|
EnsureFormInCurrentScreen();
|
|
//Screen screen = Screen.FromControl(this);
|
|
//this.MaximumSize = screen.WorkingArea.Size;
|
|
}
|
|
this.WindowState = this.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal;
|
|
if (this.WindowState == FormWindowState.Maximized)
|
|
{
|
|
this.Padding = new Padding(0, 0, 0, 0);
|
|
}
|
|
else if (this.WindowState == FormWindowState.Normal)
|
|
{
|
|
this.Padding = new Padding(0, 0, 3, 3);
|
|
}
|
|
this.mainPanelControlEx.State = this.WindowState;
|
|
this.StartPosition = FormStartPosition.CenterScreen;
|
|
this.ResetFormState();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:窗口最小化</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void OnMinButtonCallBack(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.WindowState = FormWindowState.Minimized;
|
|
this.ResetFormState();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:关闭界面后清除之前打开的模块</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="FormClosingEventArgs"/> instance containing the event data.</param>
|
|
private void OnFormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
CloseWatermarkForm();
|
|
Manager.ModuleForms.Clear();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标放开</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void OnTopMouseDownCallback(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
base.OnMouseDown(e);
|
|
System.Windows.Forms.Control control = (System.Windows.Forms.Control)sender;
|
|
Point mousePoint = control.PointToClient(System.Windows.Forms.Control.MousePosition);
|
|
_mousePostion = new Point(mousePoint.X, mousePoint.Y);
|
|
_isMouseDown = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标按下</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void OnTopMouseMoveCallBack(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
base.OnMouseMove(e);
|
|
if (_isMouseDown && e.Button == MouseButtons.Left)
|
|
{
|
|
this.Location = new Point(Location.X + (e.X - _mousePostion.X), Location.Y + (e.Y - _mousePostion.Y));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标移动</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void OnTopMouseUpCallBack(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
base.OnMouseUp(e);
|
|
_isMouseDown = false;
|
|
//this.Focus();
|
|
if (this.WindowState == FormWindowState.Normal)
|
|
{
|
|
EnsureFormInCurrentScreen();
|
|
}
|
|
this.mainPanelControlEx.pic_search.Focus();//点击界面失去焦点
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
#region 无标题栏窗体最大化最小化
|
|
protected override CreateParams CreateParams
|
|
{
|
|
get
|
|
{
|
|
const int WS_MINIMIZEBOX = 0x00020000; // Winuser.h中定义
|
|
CreateParams cp = base.CreateParams;
|
|
cp.Style = cp.Style | WS_MINIMIZEBOX; // 允许最小化操作
|
|
return cp;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// <para>说明:检测当前内容占用清空</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-06-02 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void ContentDetection(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
MEMORY_INFO MemInfo;
|
|
MemInfo = new MEMORY_INFO();
|
|
|
|
GlobalMemoryStatus(ref MemInfo);
|
|
//Console.WriteLine(MemInfo.dwMemoryLoad.ToString() + "%的内存正在使用");
|
|
string footprint = MemInfo.dwMemoryLoad.ToString();
|
|
ClearMemory();
|
|
//if (double.Parse(footprint) >= 90)
|
|
//{
|
|
|
|
//}
|
|
//int WorkingSetLinex = System.Diagnostics.Process.GetCurrentProcess().MaxWorkingSet.ToInt32();
|
|
//string WorkingSetLinex2 = (WorkingSetLinex / 1024 / 1024).ToString();
|
|
//string WorkingSetLinex = Marshal.PtrToStringAnsi(System.Diagnostics.Process.GetCurrentProcess().MaxWorkingSet);
|
|
//PerformanceCounter ramCounter = new PerformanceCounter("Process", "Working Set", name);
|
|
//float ram2 = ramCounter.NextValue();
|
|
//string ram = String.Format("{0:F}", ramCounter.NextValue() / 1024 / 1024);
|
|
//PerformanceCounter AllocateRam = new PerformanceCounter("Process", "Working Set - Private", name);
|
|
//float pf = AllocateRam.NextValue();
|
|
//string workingSe = String.Format("{0:F}", AllocateRam.NextValue() / 1024 );
|
|
//PerformanceCounter sqdx = new PerformanceCounter("Process", "Virtual Bytes", name);
|
|
//float sqdx1 = sqdx.NextValue();
|
|
//string sqdx2 = String.Format("{0:F}", sqdx.NextValue() / 1024 / 1024);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
[DllImport("User32.dll")]
|
|
public static extern IntPtr GetForegroundWindow(); //获取活动窗口句柄
|
|
[DllImport("User32.dll", CharSet = CharSet.Auto)]
|
|
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID); //获取线程ID
|
|
[DllImport("kernel32")]
|
|
public static extern void GetSystemDirectory(StringBuilder SysDir, int count);
|
|
[DllImport("kernel32")]
|
|
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
|
|
[DllImport("kernel32")]
|
|
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
|
|
[DllImport("kernel32")]
|
|
public static extern void GetSystemTime(ref SYSTEMTIME_INFO stinfo);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct CPU_INFO
|
|
{
|
|
public uint dwOemId;
|
|
public uint dwPageSize;
|
|
public uint lpMinimumApplicationAddress;
|
|
public uint lpMaximumApplicationAddress;
|
|
public uint dwActiveProcessorMask;
|
|
public uint dwNumberOfProcessors;
|
|
public uint dwProcessorType;
|
|
public uint dwAllocationGranularity;
|
|
public uint dwProcessorLevel;
|
|
public uint dwProcessorRevision;
|
|
}
|
|
//定义内存的信息结构
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct MEMORY_INFO
|
|
{
|
|
public uint dwLength;
|
|
public uint dwMemoryLoad;
|
|
public uint dwTotalPhys;
|
|
public uint dwAvailPhys;
|
|
public uint dwTotalPageFile;
|
|
public uint dwAvailPageFile;
|
|
public uint dwTotalVirtual;
|
|
public uint dwAvailVirtual;
|
|
}
|
|
//定义系统时间的信息结构
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct SYSTEMTIME_INFO
|
|
{
|
|
public ushort wYear;
|
|
public ushort wMonth;
|
|
public ushort wDayOfWeek;
|
|
public ushort wDay;
|
|
public ushort wHour;
|
|
public ushort wMinute;
|
|
public ushort wSecond;
|
|
public ushort wMilliseconds;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 多屏时设置程序大小
|
|
/// </summary>
|
|
private void EnsureFormInCurrentScreen()
|
|
{
|
|
if (this.WindowState != FormWindowState.Normal)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Screen screen = Screen.FromPoint(System.Windows.Forms.Control.MousePosition);
|
|
Rectangle workingArea = screen.WorkingArea;
|
|
|
|
int width = this.Width;
|
|
int height = this.Height;
|
|
|
|
if (width > workingArea.Width)
|
|
{
|
|
width = workingArea.Width;
|
|
}
|
|
|
|
if (height > workingArea.Height)
|
|
{
|
|
height = workingArea.Height;
|
|
}
|
|
|
|
int left = this.Left;
|
|
int top = this.Top;
|
|
|
|
if (left < workingArea.Left)
|
|
{
|
|
left = workingArea.Left;
|
|
}
|
|
|
|
if (top < workingArea.Top)
|
|
{
|
|
top = workingArea.Top;
|
|
}
|
|
|
|
if (left + width > workingArea.Right)
|
|
{
|
|
left = workingArea.Right - width;
|
|
}
|
|
|
|
if (top + height > workingArea.Bottom)
|
|
{
|
|
top = workingArea.Bottom - height;
|
|
}
|
|
|
|
this.MaximumSize = workingArea.Size;
|
|
this.Bounds = new Rectangle(left, top, width, height);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|