麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

DotNET WinForm FAQ 16個(下)

2024-07-21 02:21:08
字體:
來源:轉載
供稿:網友
菜鳥學堂:
9. 如何制作一個mdi的窗體

1. 建立一個新的windows application項目

2. 分別加入兩個窗體form1 、form2

3. 設置form1的ismdicontainer屬性為true。使它成為mdi主窗體。

4. 在form2中加入一個richtextbox控件,并設置dock為:fill

5. 在tools 窗體中拖一個mainmenu到窗體form1,然后建立一個菜單file|windows|help三個菜單項,file中包括new、exit菜單項;windows中包括cascade、horizontal等。

6. 設置windows菜單項的mdilist屬性=true, 這樣每一個mdi子窗口將自動加在windows菜單項下面。

7. 雙擊new菜單項,然后加入以下代碼:

private void menunew_click(object sender, system.eventargs e)

{

form2 newmdichild ;

newmdichild = new form2() ;

newmdichild.mdiparent = this ;

newmdichild.show() ;



}

8. 在windows的cascade等菜單項中加入以下代碼:

private void menuwindowcasca_click(object sender, system.eventargs e)

{

this.layoutmdi( mdilayout.cascade) ;



}

另外還有以下常用的:

this.layoutmdi(mdilayout.tilehorizontal);

this.layoutmdi(mdilayout.tilevertical);

9. f5運行。

最終版的vs.net 不知是否會有一個通用的模板,不過用完全手工的方式產生一個mdi的窗口,顯得有些繁瑣,不如vs.net的ide方式下那么簡潔。



10. 如何將你的窗體不顯示在任務條上.

當窗體的邊界風格是tools window時它都不會出現在任務條上的.另外上面標題5中介紹的方法不僅窗體看不見,也不會出現在任務條上.

如果你現在在dotnet的世界,這件事也變的簡單,任何的winform窗體現在都有showintaskbar屬性,所以你只要簡單的設置這個屬性就可以了。同樣你可以選擇在屬性窗口中將showintaskbar由true改為false。或是用代碼的方式:

mytaskbarfrm.showintaskbar = false ; ( c# )



11. 如何制作一個帶啟動屏幕的窗體.

需要你準備兩個winform的窗體,一個叫它:splashscreen,把它做成一個漂亮的窗體。然后你需要一個主窗體叫它:form1吧,然后在這個窗體加入下面的代碼。

// ( c# )

protected override void onload ( system.eventargs e )

{

//make load take a long time

thread.sleep(2000);



base.onload(e);



}

然后在main中加入這樣的代碼:

[stathread]

static void main()

{

splashscreen splashform = new splashscreen();

splashform.show();



form1 mainform = new form1() ;

mainform.load += new eventhandler(splashform.mainscreen_load);

application.run(mainform);



}

不要忘了加上對threading的引用: using system.threading;



12. 如何使你的窗體trayicon.

實現這個功能你可以運用notifyicon控件來達到,從tools windows中將notifyicon拖到你的窗體上然后在下面的事件加入如下代碼,f5。



' // vb.net

private micona as icon = new icon("icon1.ico")

private miconb as icon = new icon("icon2.ico")

private micondisplayed as boolean



public sub new()

mybase.new



form1 = me



'this call is required by the win form designer.

initializecomponent



'todo: add any initialization after the initializecomponent() call



'this form isn't used directly so hide it immediately

me.hide()



'setup the tray icon

initializenotifyicon()

end sub



private sub initializenotifyicon()

'setup the default icon

notifyicon = new system.windows.forms.notifyicon()

notifyicon.icon = micona

notifyicon.text = "right click for the menu"

notifyicon.visible = true

micondisplayed = true



'insert all menuitem objects into an array and add them to

'the context menu simultaneously

dim mnuitms(3) as menuitem

mnuitms(0) = new menuitem("show form...", new eventhandler(addressof me.showformselect))

mnuitms(0).defaultitem = true

mnuitms(1) = new menuitem("toggle image", new eventhandler(addressof me.toggleimageselect))

mnuitms(2) = new menuitem("-")

mnuitms(3) = new menuitem("exit", new eventhandler(addressof me.exitselect))

dim notifyiconmnu as contextmenu = new contextmenu(mnuitms)

notifyicon.contextmenu = notifyiconmnu

end sub



public sub showformselect(byval sender as object, byval e as system.eventargs)

'display the settings dialog

dim settingsform as new settingsform()

settingsform.showdialog()



end sub



public sub toggleimageselect(byval sender as object, byval e as system.eventargs)

'called when the user selects the 'toggle image' context menu



'determine which icon is currently visible and switch it

if micondisplayed then

'called when the user selects the 'show form' context menu

notifyicon.icon = miconb

notifyicon.text = "sad"

micondisplayed = false

else

notifyicon.icon = micona

notifyicon.text = "happy"

micondisplayed = true

end if



end sub



public sub exitselect(byval sender as object, byval e as system.eventargs)

'called when the user selects the 'exit' context menu



'hide the tray icon

notifyicon.visible = false



'close up

me.close()

end sub



'form overrides dispose to clean up the component list.

public overloads overrides sub dispose()

mybase.dispose()

components.dispose()

end sub

圖標文件你自己準備了,如果成功你可以看到有關notifyicond的各種功能了。



13. 如何修改控制窗體的尺寸和長寬尺寸.

主要是修改winform的size, width 和height屬性。同樣它們都是可以在設計和運行時刻進行修改和設置。

form1.size = new system.drawing.size(100, 100) ( vb.net )

form1.width += 100 (vb.net )

form1.height -= 20 (vb.net )



14. 如何建立一個windows explorer風格的窗體.

1.建立一個新的windows application

2.從toolbox窗口拖一個treeview控件、、一個splitterk控件、一個listview控件,分別在屬性窗口中設置treeview的dock屬性為::left;設置listview控件的dock屬性為:fill

3: f5 運行



15. 如何設置初始的啟動窗體

無論是c#還是visual basic的winform項目中你都可以在solution explorer窗口中右鍵你的project,然后選擇屬性,從你project的屬性頁中選擇你啟動的窗體或是main()方法。

有些不同的是在目前的vs.net beta2中c#項目會自動產生main() 方法,visual basic.net 的項目中你必須自己添加main()代碼,c#中你可以將form1改成任何你可以啟動的窗體名:

// ( c# )

static void main()

{

application.run(new form1());

}



16. 如何建立一個有背景圖像的窗體

現在的winform中所有的窗體都有一個backgroundimage屬性,只用對它賦值就可以了。普通窗體可以在運行模式也可以在運行模式完成這個設置。比如在initializecomponent()或窗體的構造函數中加入這樣的代碼:

this.backgroundimage = new bitmap("c://dotnetapp//winform//tile.bmp" ) ;

對于mdi的主窗體要麻煩一些,在vs.net的ide窗體中,當你設置完ismdicontainer屬性為true后,你需要查看一下initializecomponent()中是否有這樣的代碼 ( c# ):

this.mdiclient1.dock = system.windows.forms.dockstyle.fill;

this.mdiclient1.name = "mdiclient1";

或是在窗口的屬性窗口組合框中看到mdiclient1 system.windows.forms.mdiclient.這就是主mdi窗口,不過我沒有在dotnet的文檔中找到任何有關system.windows.forms.mdiclient的說明。然后你可以在initializecomponent()或窗體的構造函數中加入這樣的代碼( c# ):

this.mdiclient1.backgroundimage = new bitmap("c://dotnetapp//winform//tile.bmp" ) ;

網上有一個imageview的例子,里面演示了給mdi主窗體中背景上加入一行logo文字的方法,這樣使你的mdi窗體看起來很商業化,具體的你可以這樣做:

1. 先在vs.net 自動產生代碼的initializecomponent中看是否有這樣的語句( c# ):

this.controls.addrange(new system.windows.forms.control[] {this.mdiclient1});

又是這個mdiclient (haha)

2. 建立以下兩個函數用于顯示這個logo字符:

// ( c# )

protected void mdi_onpaint ( object s, system.windows.forms.painteventargs e )

{

control c = (control)s;





rectangle r1 = c.clientrectangle;

r1.width -= 4;

r1.height -= 4;



rectangle r2 = r1;

r2.width -= 1;

r2.height -= 1;



font f = new font("tahoma", 8);



string str = "mywinform.net ?2001 mywinform application v1.0";



stringformat sf = new stringformat();

sf.alignment = stringalignment.far;

sf.linealignment = stringalignment.far;



e.graphics.drawstring(str, f, new solidbrush(systemcolors.controldarkdark), r1, sf);

e.graphics.drawstring(str, f, new solidbrush(systemcolors.controllight), r2, sf);



}



protected void mdi_onresize ( object s , system.eventargs e )

{



control c = (control)s;

c.invalidate();

}

3. 在initializecomponent()或窗體的構造函數中加入這樣的代碼:

( c# )

this.controls[0].paint += new painteventhandler( mdi_onpaint ) ;

this.controls[0].resize += new eventhandler( mdi_onresize ) ;

注意將它加在initializecomponent()后面或是在initializecomponent函數中this.controls.addrange函數之后。



--------------------------------------------------------------------------------


總的看來,整個winform部分始終透著hejlsberg設計vj++中wfc庫的氣息,現在還沒有任何線索能證明dotnet是照搬wfc庫,但我還是相信delphi和vj++的用戶會更容易感受到hejlsberg的設計風格,比如事件委托在幾年前就被視為領先而嚴重違背“純java”原則而使開發人員陷入尷尬,現在我們可以很自然的享受這種特性,但另一方面dotnet和java或delphi似乎靠得更近些,你幾乎不能像mfc時代那樣去從源代碼中找尋秘密和內幕了。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 精品影视一区二区 | 小视频成人 | 成人综合免费视频 | 日本中文字幕久久 | 九九热在线视频观看这里只有精品 | 久久国产精品小视频 | 色视频欧美 | 日韩精品久久久久久久电影99爱 | 欧美黄色免费视频 | 黄色片网站免费观看 | 中文字幕在线观看网址 | aa国产视频一区二区 | www.com香蕉| 国产精品一区二区三区99 | 黄色片一区二区 | 嗯哈~不行好大h双性 | 欧美精品日日鲁夜夜添 | 欧美一级棒 | 九九热在线免费观看视频 | 哪里可以看免费的av | 精品免费国产一区二区三区 | 国产精品久久久久久婷婷天堂 | 麻豆传传媒久久久爱 | 亚洲国产精品久久久 | 羞羞视频免费视频欧美 | 老师你怎么会在这第2季出现 | 久久精品一区二区三区国产主播 | 92看片淫黄大片一级 | 国产成年人网站 | av电影网站在线 | 中文字幕精品在线视频 | 久久久精品视频免费看 | 亚洲天堂中文字幕在线观看 | 欧美 国产 综合 | 国产亚洲精品综合一区91 | 欧美国产精品久久 | 欧美××××黑人××性爽 | 欧美日韩一 | 特一级毛片 | 国产精品一区99 | 久久国产在线观看 |