日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
淺析C#WinForm控件開發(fā)前期準(zhǔn)備

對于C# WinForm控件開發(fā),MSDN上提供了很多使用的方法,那么這里就向你介紹對于C# WinForm控件開發(fā)的基本了解內(nèi)容,C#開發(fā)WinForm控件的類型以及各自的特點(diǎn)。

目前創(chuàng)新互聯(lián)公司已為上千多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、荷塘網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

C# WinForm控件開發(fā)的伊始:

其實(shí)C#開發(fā)WinForm控件并不是很復(fù)雜,.NET為我們提供了豐富的底層支持。如果你有MFC或者API圖形界面的開發(fā)經(jīng)驗(yàn),那么學(xué)會(huì)WinForm控件可能只需要很短的時(shí)間就夠了。

自己開發(fā)的WinForm控件通常有三種類型:復(fù)合控件(Composite Controls),擴(kuò)展控件(Extended Controls),自定義控件(Custom Controls)。

◆復(fù)合控件:將現(xiàn)有的各種控件組合起來,形成一個(gè)新的控件,將集中控件的功能集中起來。

◆擴(kuò)展控件:在現(xiàn)有控件的控件的基礎(chǔ)上派生出一個(gè)新的控件,為原有控件增加新的功能或者修改原有控件的控能。

◆自定義控件:直接從System.Windows.Forms.Control類派生出來。Control類提供控件所需要的所有基本功能,包括鍵盤和鼠標(biāo)的事件處理。自定義控件是最靈活最強(qiáng)大的方法,但是對開發(fā)者的要求也比較高,你必須為Control類的OnPaint事件寫代碼,你也可以重寫Control類的WndProc方法,處理更底層的Windows消息,所以你應(yīng)該了解GDI+和Windows API。

C# WinForm控件開發(fā)之控件(可視化的)的基本特征:

1. 可視化。

2. 可以與用戶進(jìn)行交互,比如通過鍵盤和鼠標(biāo)。

3. 暴露出一組屬性和方法供開發(fā)人員使用。

4. 暴露出一組事件供開發(fā)人員使用。

5. 控件屬性的可持久化。

6. 可發(fā)布和可重用。

這些特征是我自己總結(jié)出來,不一定準(zhǔn)確,或者還有遺漏,但是基本上概括了控件的主要方面。

接下來我們做一個(gè)簡單的控件來增強(qiáng)一下感性認(rèn)識。首先啟動(dòng)VS2005創(chuàng)建一個(gè)ClassLibrary工程,命名為CustomControlSample,VS會(huì)自動(dòng)為我們創(chuàng)建一個(gè)solution與這個(gè)工程同名,然后刪掉自動(dòng)生成的Class1.cs文件,最后在Solution explorer里右鍵點(diǎn)擊CustomControlSample工程選擇Add->Classes…添加一個(gè)新類,將文件的名稱命名為FirstControl。下邊是代碼:

 
 
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. namespace CustomControlSample
  8. {
  9. public class FirstControl : Control
  10. {
  11. public FirstControl()
  12. {
  13. }
  14. // ContentAlignment is an enumeration defined in the System.Drawing
  15. // namespace that specifies the alignment of content on a drawing 
  16. // surface.
  17. private ContentAlignment alignmentValue = ContentAlignment.MiddleLeft;
  18. [
  19. Category("Alignment"),
  20. Description("Specifies the alignment of text.")
  21. ]
  22. public ContentAlignment TextAlignment
  23. {
  24. get
  25. {
  26. return alignmentValue;
  27. }
  28. set
  29. {
  30. alignmentValue = value;
  31. // The Invalidate method invokes the OnPaint method described 
  32. // in step 3.
  33. Invalidate();
  34. }
  35. }
  36. protected override void OnPaint(PaintEventArgs e)
  37. {
  38. base.OnPaint(e);
  39. StringFormat style = new StringFormat();
  40. style.Alignment = StringAlignment.Near;
  41. switch (alignmentValue)
  42. {
  43. case ContentAlignment.MiddleLeft:
  44. style.Alignment = StringAlignment.Near;
  45. break;
  46. case ContentAlignment.MiddleRight:
  47. style.Alignment = StringAlignment.Far;
  48. break;
  49. case ContentAlignment.MiddleCenter:
  50. style.Alignment = StringAlignment.Center;
  51. break;
  52. }
  53. // Call the DrawString method of the System.Drawing class to write 
  54. // text. Text and ClientRectangle are properties inherited from
  55. // Control.
  56. e.Graphics.DrawString(
  57. Text,
  58. Font,
  59. new SolidBrush(ForeColor),
  60. ClientRectangle, style);
  61. }
  62. }
  63. }

C# WinForm控件開發(fā)的基本前期需要了解的內(nèi)容就向你介紹到這里,希望對你進(jìn)行C# WinForm控件開發(fā)有所幫助。


網(wǎng)站標(biāo)題:淺析C#WinForm控件開發(fā)前期準(zhǔn)備
轉(zhuǎn)載來源:http://m.5511xx.com/article/cdgdjog.html