在项目中,有时对界面的控制是这样的,需要在当前界面操作未完成时不允许另外的界面进行操作,于是有了下面的代码:
1![]()
/**/ /// <summary>
2/// 控制系统维护界面当点击按钮时,对界面进行暂时锁定
3/// Add by: Maxc
4/// </summary>
5public class SetUserControlEnable
6![]()
{
7[DllImport("user32.dll")]
8private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc);
9
10[DllImport("user32.dll")]
11private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
12
13private const int GWL_STYLE = -16;
14private const int WS_DISABLED = 0x8000000;
15
16private static void SetControlEnabled(Control c, bool enabled)
17![]()
{
18if (enabled)
19![]()
{ SetWindowLong(c.Handle, GWL_STYLE, (~WS_DISABLED) & GetWindowLong(c.Handle, GWL_STYLE)); }
20else
21![]()
{ SetWindowLong(c.Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(c.Handle, GWL_STYLE)); }
22}
23
24当点击按钮的时候,让所有界面都被锁定 private void LockAllInterface()#region 当点击按钮的时候,让所有界面都被锁定 private void LockAllInterface()
25/**//// <summary>
26/// 当点击按钮的时候,让所有界面都被锁定
27/// </summary>
28public static void Lock()
29![]()
{
30SetControlEnabled(MainContext.ms_SystemMainForm.panelFunction, false);
31SetControlEnabled(MainContext.ms_SystemMainForm.panelTitle, false);
32SetControlEnabled(MainContext.ms_SystemMainForm.panelMain, false);
33}
34#endregion
35
36点击之后,所有界面都被解锁 private void UnlockAllInterface()#region 点击之后,所有界面都被解锁 private void UnlockAllInterface()
37/**//// <summary>
38/// 点击之后,所有界面都被解锁
39/// </summary>
40public static void UnLock()
41![]()
{
42SetControlEnabled(MainContext.ms_SystemMainForm.panelFunction, true);
43SetControlEnabled(MainContext.ms_SystemMainForm.panelTitle, true);
44SetControlEnabled(MainContext.ms_SystemMainForm.panelMain, true);
45}
46#endregion
47}
通过上述代码就可实现想要的效果了。
转载于:https://www.cnblogs.com/winnxm/archive/2008/02/29/1086525.html