自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C# ListBox學(xué)習(xí)筆記

開發(fā) 后端
本文介紹C# ListBox,以及介紹為 MeasureItem 事件創(chuàng)建事件處理程序,以在 DrawItem 事件的事件處理程序中指定要繪制的項的大小。

學(xué)習(xí)C# ListBox使用,僅當(dāng) DrawMode 屬性設(shè)置為 DrawMode.OwnerDrawFixed 或 DrawMode.OwnerDrawVariable 時,才引發(fā)該事件。可以使用該事件來執(zhí)行在C# ListBox 中繪制項所需的任務(wù)。如果具有大小可變的項(當(dāng) DrawMode 屬性設(shè)置為 DrawMode.OwnerDrawVariable 時),在繪制項前,引發(fā) MeasureItem 事件??梢詾?MeasureItem 事件創(chuàng)建事件處理程序,以在 DrawItem 事件的事件處理程序中指定要繪制的項的大小。有關(guān)處理事件的更多信息,請參見 使用事件。

重寫C# Listbox的drawitem事件

  1. privatevoidlistBox1_DrawItem(objectsender,System.Windows.Forms.DrawItemEventArgse){  
  2. //SettheDrawModepropertytodrawfixedsizeditems.  
  3. listBox1.DrawMode=DrawMode.OwnerDrawFixed;  
  4. //DrawthebackgroundoftheListBoxcontrolforeachitem.  
  5. e.DrawBackground();  
  6. //Definethedefaultcolorofthebrushasblack.  
  7. BrushmyBrush=Brushes.Black;  
  8. //Determinethecolorofthebrushtodraweachitembasedontheindexoftheitemtodraw.  
  9. switch(e.Index){  
  10. case0:myBrush=Brushes.Red;break;  
  11. case1:myBrush=Brushes.Orange;break;  
  12. case2:myBrush=Brushes.Purple;break;  
  13. }  
  14. //DrawthecurrentitemtextbasedonthecurrentFontandthecustombrushsettings.  
  15. e.Graphics.DrawString(listBox1.Items[e.Index].ToString(),e.Font,myBrush,  
  16. e.Bounds,StringFormat.GenericDefault);  
  17. //IftheListBoxhasfocus,drawafocusrectanglearoundtheselecteditem.  
  18. e.DrawFocusRectangle();  

從這個例子,我們發(fā)現(xiàn)在C#下面重畫控件,比在vc++6.0中定義自繪方便多了

【編輯推薦】

  1. 概述C#實現(xiàn)文件下載
  2. C#搞定網(wǎng)站驗證碼的方法
  3. 淺談C# String對象
  4. C#命名空間學(xué)習(xí)筆記
  5. 淺析C#調(diào)用ActiveX控件
責(zé)任編輯:佚名 來源: 百度空間
相關(guān)推薦

2009-08-19 11:21:02

C# ListBox控

2009-08-14 14:19:50

Enhanced LiC#構(gòu)建

2009-09-08 15:39:00

2009-08-12 09:28:36

C# WiteOne

2009-08-13 18:21:52

C#學(xué)習(xí)筆記

2009-08-20 15:02:57

C# If語句

2009-09-08 17:37:54

C# listbox控

2009-04-12 08:55:18

Symbian諾基亞移動OS

2009-08-26 10:48:44

C# SQL命令

2009-08-31 15:27:33

C# TreeView

2009-08-24 15:46:46

C# SmartPho

2009-08-21 17:53:28

C#查詢結(jié)果

2009-08-24 14:30:49

C# WMI封裝

2009-08-25 15:26:03

C#調(diào)用ImOK

2009-08-12 10:46:54

C#命名空間

2009-09-08 16:10:03

C# ListBox

2009-09-08 15:12:07

C# ListBox

2009-09-10 12:00:09

C# listbox

2009-09-08 16:34:49

C# Listbox

2009-08-14 15:54:12

C#編程語言
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號