c 顯示隱藏的窗體和托盤中的程式

2021-06-20 22:56:50 字數 802 閱讀 7098

將程式最小化到托盤已經是最常用的操作,但在c#中憑藉 form1.visible=true; 抑或是form1.topmost=true; 只能將窗體顯示在工作列中,而不能將窗體直接顯示給使用者,這無疑是糟糕的使用者體驗。為了實現上述目的,我們需要借助於win32函式:

#region win32函式

[dllimport("user32.dll")]

public static extern intptr findwindow(string lpspecifiedclassname, string lpwindowname);

[dllimport("user32.dll ", setlasterror = true)]

public static extern void switchtothiswindow(intptr hwnd, bool falttab);

[dllimport("user32.dll", entrypoint = "showwindow", charset = charset.auto)]

public static extern int showwindow(intptr hwnd, int ncmdshow);

public const int sw_restore = 9;

public static intptr formhwnd;

#endregion

intptr frm = form1.handle; //得到窗體控制代碼

showwindow(frm, 9); //顯示窗體

switchtothiswindow(frm, true); //切換到窗體

窗體中新增控制項與窗體顯示和隱藏

對於乙個應用程式而言,控制項是使用者介面的積木,他們具備互動式的特徵 新增控制項的方法 拖 拉 拽 新增控制項的另一種方法 即通過窗體的controls類的 add方法,格式如下 窗體的標誌.controls.add 控制項識別符號 例子 建立乙個 mybut 乙個物件 button mybut n...

窗體傳值中的顯示和關閉窗體

private showinfomsg form if this.form null 判斷是否例項化 form new showinfomsg form.show else if this.form.isdisposed 判斷子窗體是否關閉 from null 如果關閉先釋放資源 form new ...

顯示和隱藏DataGrid中的列

要顯示和隱藏datagrid中的列,最關鍵的是autogeneratecolumns設定為false 下面就是實現這一功能的aspx 和指令碼 page language vb autoeventwireup false codebehind showhidecols.aspx.vb inherit...