?? 基于vc_net的gdi+編程入門之畫刷 _1.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0046)http://www.qqread.com/vcdotnet/f482126000.html -->
<HTML lang=zh xml:lang="zh" xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>基于VC.NET的GDI+編程入門之畫刷 - QQread.com 電腦頻道</TITLE>
<META http-equiv=Content-Language content=zh-CN>
<META
content=[art_mtkw],電腦入門,上網(wǎng)指南,操作系統(tǒng),常用軟件,黑客與安全,網(wǎng)絡(luò)游戲,程序開發(fā),數(shù)據(jù)庫開發(fā),網(wǎng)頁制作,圖像處理,多媒體制作,網(wǎng)絡(luò)編程,加密技術(shù),網(wǎng)絡(luò)技術(shù)
name=keywords>
<META content=基于VC.NET的GDI+編程入門之畫刷 name=description>
<META content=QQRead.com name=author>
<META content=all name=robots>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="基于VC_NET的GDI+編程入門之畫刷 _1.files/qqread_html.css" type=text/css
rel=stylesheet><LINK href="基于VC_NET的GDI+編程入門之畫刷 _1.files/qqread_html_com.css"
type=text/css rel=stylesheet>
<STYLE type=text/css>.STYLE2 {
FONT-SIZE: 14px
}
</STYLE>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY><!-- 公共頁頭 -->
<DIV style="TEXT-ALIGN: center">
<DIV id=topad>
<TABLE>
<TBODY>
<TR>
<TD width=10><SPAN
id=ad_qqread_top></SPAN><!--End//--></TD></TR></TBODY></TABLE></DIV>
<DIV id=CHBig>
<DIV id=CHBigCSDNLogo><A href="http://www.qqread.com/"><IMG alt=巧巧讀書網(wǎng)
src="基于VC_NET的GDI+編程入門之畫刷 _1.files/qqread.gif" border=0></A></DIV>
<DIV id=CHBigHeaderWrapper>
<DIV id=CHBigNavBar2>
<UL>
<LI><A href="http://www.qqread.com/news/" target=_blank>新聞中心</A>|
<LI><A href="http://www.qqread.com/skill/" target=_blank>技巧集錦</A>|
<LI><A href="http://www.qqread.com/itlife/" target=_blank>IT人生雨露</A>|
<LI><A href="http://www.qqread.com/pcbase/" target=_blank>電腦入門</A>|
<LI><A href="http://www.qqread.com/netreference/" target=_blank>上網(wǎng)指南</A>|
<LI><A href="http://www.qqread.com/safe/" target=_blank>黑客與安全</A>|
<LI><A href="http://www.qqread.com/commentsoft/" target=_blank>常用軟件</A>|
<LI><A href="http://www.qqread.com/os/" target=_blank>操作系統(tǒng)</A>|
<LI><A href="http://www.qqread.com/netgame/" target=_blank>網(wǎng)絡(luò)游戲</A><BR>
<LI><A title=圖片欣賞 href="http://www.qqread.com/photo/index.html"
target=_blank>圖片欣賞</A>|
<LI><A href="http://www.qqread.com/program/" target=_blank>程序開發(fā)</A>|
<LI><A href="http://www.qqread.com/database/" target=_blank>數(shù)據(jù)庫開發(fā)</A>|
<LI><A href="http://www.qqread.com/webdesign/" target=_blank>網(wǎng)頁制作</A>|
<LI><A href="http://www.qqread.com/photohandle/" target=_blank>圖像處理</A>|
<LI><A href="http://www.qqread.com/mutimedia/" target=_blank>多媒體制作</A>|
<LI><A href="http://www.qqread.com/netprogram/" target=_blank>網(wǎng)絡(luò)編程</A>|
<LI><A href="http://www.qqread.com/encrypt/" target=_blank>加密技術(shù)</A>|
<LI><A href="http://www.qqread.com/network/" target=_blank>網(wǎng)絡(luò)技術(shù)</A>
</LI></UL></DIV>
<DIV id=CHBigNavBar1></DIV></DIV>
<DIV style="CLEAR: both"></DIV></DIV></DIV><!-- /公共頁頭 -->
<DIV id=OutBox>
<DIV id=listMainArea>
<DIV id=disclaimer><A href="http://www.qqread.com/">巧巧讀書首頁</A> > <A
title=程序開發(fā) href="http://www.qqread.com/program/index.html">程序開發(fā)</A> > <A
title=.Net技術(shù) href="http://www.qqread.com/dotnet/index.html">.Net技術(shù)</A> > <A
title=VC.NET href="http://www.qqread.com/vcdotnet/index.html">VC.NET</A> >
正文</DIV>
<DL class=ReadArticle>
<DT>基于VC.NET的GDI+編程入門之畫刷
<DD class=ArticleInfo3>
<SCRIPT src="基于VC_NET的GDI+編程入門之畫刷 _1.files/adtitle.js"
type=text/javascript></SCRIPT>
<HR SIZE=2>
<DD class=ArticleInfo3>
<DIV align=center><A href="http://www.qqread.com/">http://www.qqread.com/</A>
作者:劉濤 2005-12-03 來源:天極網(wǎng) 瀏覽:<SPAN id=count></SPAN> </DIV>
<DD class=ArticleInfo_3>
<DD class=ArticleInfo_3><A
href="http://www.qqread.com/vcdotnet/f482126000_2.html">下一頁</A> <FONT
color=#ff0000>1</FONT> <A
href="http://www.qqread.com/vcdotnet/f482126000_2.html">2</A> <A
href="http://www.qqread.com/vcdotnet/f482126000_3.html">3</A> <A
href="http://www.qqread.com/vcdotnet/f482126000_4.html">4</A>
<DD
class=ArticleContent> 基于線條的、封閉的圖形需要畫筆來表現(xiàn),封閉的形狀的典型的特點在于它可以用圖形、顏色或模式來填充。<BR><BR>
<TABLE style="MARGIN: 10px 8px 3px 7px" cellSpacing=0 cellPadding=0 align=left
border=0>
<TBODY>
<TR>
<TD><SPAN
id=ad_qqread_mid_big></SPAN></TD></TR></TBODY></TABLE> 畫刷是具有顏色,圖形或模式的對象,它用來填充圖形內(nèi)部,這種定義也意味著根據(jù)不同的目的有不同的畫刷。為了滿足這一目標(biāo),.NET框架在不同的名字空間中使用不同的類來支持畫刷。所有畫刷的基類是Brush類,它定義在System::Drawing名字空間中。<BR><BR> <B>一、使用畫刷</B><BR><BR> 因為畫刷的主要工作是填充封閉的圖形,Graphics類為每一中圖形都提供了一個填充方法。這些方法是:<BR><BR> ·FillRectangle:
填充一個矩形或一個正方形; <BR> ·FillRectangle: 填充一系列的矩形; <BR> ·FillEllipse: 填充橢圓或圓
<BR> ·FillPolygon: 填充多邊形<BR> ·FillPie:
填充餅圖<BR> ·FillPath:填充圖形路徑<BR><BR> 為了填寫一個圖形,調(diào)用上述的一個方法,給它傳遞一個刷子值,然后是圖形的位置和尺寸,例如,如果想繪制一個矩形并用一個畫刷來填充它,可以使用與下面相似的代碼:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1><TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object *
sender,PaintEventArgs *
e)<BR>{<BR>e->Graphics->FillRectangle(SomeBrush, 20, 20, 200,
160);<BR>}</TD></TR></TBODY></TABLE><BR> 總共有四種畫刷。<BR><BR> (一)實心畫刷<BR><BR> 最簡單的畫刷就是實心的,這種畫刷只提供了一種顏色,習(xí)慣于用它來填充一個區(qū)域。為了獲得實心畫刷,可以使用System.Drawing
名字空間中的SolidBrush類。它只有一個構(gòu)造函數(shù),語法如下:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1><TBODY>
<TR>
<TD>public: SolidBrush(Color
color);</TD></TR></TBODY></TABLE><BR> color參數(shù)必須是有效定義的顏色值,這里是一個例子:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1><TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object * sender,
<BR>System::Windows::Forms::PaintEventArgs * e)<BR>{<BR>SolidBrush
*brushBlue = new
SolidBrush(Color::Blue);<BR>e->Graphics->FillRectangle(brushBlue,
20, 20, 200, 160);<BR>}</TD></TR></TBODY></TABLE><BR>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center><IMG hspace=3
src="基于VC_NET的GDI+編程入門之畫刷 _1.files/20051203ig390_1.gif" align=center
vspace=1 border=1
;?><BR>圖一、代碼運(yùn)行效果圖</DIV></TD></TR></TBODY></TABLE><BR> 如果想用不同的顏色填充不同的圖形,不必為每一個圖形創(chuàng)建一個新的畫刷,任何時候,在對一個已經(jīng)定義的畫刷進(jìn)行重用之前,只需要簡單地更改顏色,正式基于這個原因,SolidBrush類提供了顏色屬性,例子代碼如下:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1><TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object * sender,
<BR>System::Windows::Forms::PaintEventArgs * e)<BR>{<BR>SolidBrush
*colorizer = new
SolidBrush(Color::Lime);<BR>e->Graphics->FillRectangle(colorizer,
10, 10, 120, 120); <BR>colorizer->Color =
Color::Salmon;<BR>e->Graphics->FillRectangle(colorizer, 140, 10,
120, 120);<BR><BR>colorizer->Color =
Color::Aqua;<BR>e->Graphics->FillRectangle(colorizer, 10, 140,
120, 120);<BR><BR>colorizer->Color =
Color::Navy;<BR>e->Graphics->FillRectangle(colorizer, 140, 140,
120, 120);<BR>}</TD></TR></TBODY></TABLE><BR>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center><IMG hspace=3
src="基于VC_NET的GDI+編程入門之畫刷 _1.files/20051203ig390_2.gif" align=center
vspace=1 border=1
;?><BR>圖二、代碼運(yùn)行效果圖</DIV></TD></TR></TBODY></TABLE><BR> 與在圖形編程中使用的絕大部分對象一樣,畫刷消耗計算機(jī)的資源,所以,使用過它以后,需要調(diào)用
Dispose()方法來釋放它使用的資源。例子代碼如下:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1><TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object * sender,
<BR>System::Windows::Forms::PaintEventArgs * e)<BR>{<BR>SolidBrush
*colorizer = new
SolidBrush(Color::Lime);<BR>e->Graphics->FillRectangle(colorizer,
10, 10, 120, 120);<BR><BR>colorizer->Color =
Color::Salmon;<BR>e->Graphics->FillRectangle(colorizer, 140, 10,
120, 120);<BR><BR>colorizer->Color =
Color::Aqua;<BR>e->Graphics->FillRectangle(colorizer, 10, 140,
120, 120);<BR><BR>colorizer->Color =
Color::Navy;<BR>e->Graphics->FillRectangle(colorizer, 140, 140,
120, 120);<BR><BR>colorizer.Dispose();<BR>}</TD></TR></TBODY></TABLE><BR>
<DD class=ArticleContent>關(guān)鍵字: <A
href="http://www.qqread.com/keywords/file-format.html">文件格式</A> <A
href="http://www.baidu.com/baidu?tn=jkday2000&word=設(shè)計">設(shè)計</A> <A
href="http://www.qqread.com/keywords/windows.html">windows</A> <A
href="http://www.qqread.com/keywords/vcdotnet.html">vc.net</A> <A
href="http://www.qqread.com/keywords/os.html">os</A> <A
href="http://www.qqread.com/keywords/ie.html">ie</A>
<DD class=ArticleInfo_3><A
href="http://www.qqread.com/vcdotnet/f482126000_2.html">下一頁</A> <FONT
color=#ff0000>1</FONT> <A
href="http://www.qqread.com/vcdotnet/f482126000_2.html">2</A> <A
href="http://www.qqread.com/vcdotnet/f482126000_3.html">3</A> <A
href="http://www.qqread.com/vcdotnet/f482126000_4.html">4</A> </DD></DL>
<DIV id=ArticleContent4>
<SCRIPT src="基于VC_NET的GDI+編程入門之畫刷 _1.files/adend.js"
type=text/javascript></SCRIPT>
</DIV>
<TABLE style="MARGIN-BOTTOM: 5px" cellSpacing=1 cellPadding=0 width=582
align=center bgColor=#235f99 border=0>
<TBODY>
<TR bgColor=#ffffff>
<TD bgColor=#ffffff>
<SCRIPT src="基于VC_NET的GDI+編程入門之畫刷 _1.files/580.js"
type=text/javascript></SCRIPT>
<TR bgColor=#ffffff>
<TD bgColor=#ffffff><IFRAME marginWidth=0 marginHeight=0
src="基于VC_NET的GDI+編程入門之畫刷 _1.files/CA1OEH5V.htm" frameBorder=0 width=580
scrolling=no height=145></IFRAME>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -