圖形和 Windows 窗體
介紹 GDI+
公共語言運行庫使用 Windows 圖形設備接口 (GDI) 的高級版本,其名稱為 GDI+。GDI+ 旨在提供良好的性能和易用性。它支持二維圖形、版式和圖像。
新的二維功能包括下列內容:
- 對所有圖形基元的 Alpha 混合支持
- 消除鋸齒
- 漸變填充和紋理填充
- 寬線
- 基數樣條
- 可縮放區域
- 浮點坐標
- 復合線
- 嵌入鋼筆
- 高質量的篩選和縮放
- 大量的線型和筆尖選項
圖像支持包括下列內容:
- 對圖像文件格式(如 .jpeg、.png、.gif、.bmp、.tiff、.exif 和 .icon)的本機支持
- 用于編碼和解碼任意光柵圖像格式的公共接口
- 用于動態添加新圖像文件格式的可擴展結構
- 對通用點操作(如亮度、對比度、色彩平衡、模糊和溶解)的本機圖像處理支持。對通用轉換(如旋轉、裁切等)的支持。
顏色管理
對 sRGB、ICM2 和 sRGB64 的支持
版式支持包括下列內容:
- 本機 ClearType 支持
- 紋理填充和漸變填充的文本
- 在所有平臺上對 Unicode 的完全支持
- 對所有 Windows 2000 腳本的支持
- Unicode 3.0 標準的更新
- 文本行服務支持,可使文本更具可讀性
GDI+ 可與 Windows 窗體和 Web 窗體一起使用。例如,Web 窗體控件可使用基于用戶輸入的 GDI+ 動態生成 .jpeg 文件,并從 Web 頁引用它。
本節集中討論 Windows 窗體。
GDI 和 GDI+ 之間的差異
本節的目的是幫助您了解使用 GDI+ 的基礎知識。開始之前,有必要指出 GDI 和 GDI+ 之間的最大差異。GDI 具有有狀態的編程模型,而 GDI+ 具有無狀態的編程模型。使用 GDI,可在繪圖表面上設置屬性(如前景色和背景色),然后在它上面進行繪制。例如,若要繪制黑色文本字符串,代碼有點類似于下面的示例。
function doClick(index, numTabs, id) { document.all("tab" + id, index).className = "tab"; for (var i=1; i <style type="text/css"> td.code { padding:0,10,0,10; border-style:solid; border-width:1; border-bottom:0; border-top:0; border-right:0; border-color:cccccc; background-color:ffffee } td.tab { text-align:center; font:8pt verdana; width:15%; padding:3,3,3,3; border-style:solid; border-width:1; border-right:0; border-color:black; background-color:eeeeee; cursor:hand } td.backtab { text-align:center; font: 8pt verdana; width:15%; padding:3,3,3,3; border-style:solid; border-width:1; border-right:0; border-color:black; background-color:cccccc; cursor:hand } td.space { width:70%; font: 8pt verdana; padding:0,0,0,0; border-style:solid; border-bottom:0; border-right:0; border-width:1; border-color:cccccc; border-left-color:black; background-color:white } </style>
Dim g as Graphics g.ForeColor = Color.Black g.BackColor = Color.White g.Font = new Font("Times New Roman", 26) g.DrawString("Hello, World", 0, 0) |
||
C# | VB |
使用 GDI+ 時,始終將要使用的屬性作為繪圖命令的一部分傳遞。上面的代碼更改為如下所示。
Dim g As Graphics; Dim foreColor As Color = Color.Black; Dim backColor As Color = Color.White; Dim vbFont As New Font("Times New Roman", 26); g.FillRectangle(New SolidBrush(backColor), ClientRectangle); g.DrawString("Hello World", vbFont, New SolidBrush(foreColor), 15, 15); |
||
C# | VB |
GDI+ 命名空間
GDI+ 類駐留于 System.Drawing 、 System.Drawing.Drawing2D 、 System.Drawing.Imaging 和 System.Drawing.Text 命名空間中。這些命名空間包含在程序集 System.Drawing.DLL 中。
創建圖形對象
GDI+ 繪圖表面由 Graphics 類表示。為了使用 GDI+,首先需要一個對圖形對象的引用。通常,在控件或窗體的 Paint 事件中或者在
可以通過為 Paint 事件創建事件處理程序來處理該事件。
Public Class GdiPlusDemo : Inherits Form Public Sub New() ' Hook the paint event of the form. AddHandler Me.Paint, AddressOf form1_Paint End Sub Private Sub form1_Paint(sender As Object, pe As PaintEventArgs) Dim g As Graphics = pe.Graphics ' Simply fill a rectangle with red. g.FillRectangle(New SolidBrush(Color.Red), 40, 40, 140, 140) End Sub End Class |
||
C# | VB |
更常用的是,可以創建 OnPaint 方法的子類并重寫該方法。
Public Class GdiPlusDemo : Inherits Form Public Sub New() End Sub Protected Overrides Sub OnPaint(pe As PaintEventArgs) Dim g As Graphics = pe.Graphics g.FillRectangle(New SolidBrush(Color.Red), 40, 40, 140, 140) End Sub End Class |
||
C# | VB |
還可以從 Image 的任何派生類創建 Graphics 對象實例。
Dim newBitmap As Bitmap = New Bitmap(600,400,PixelFormat.Format32bppArgb) Dim g As Graphics = Graphics.FromImage(newBitmap) g.FillRectangle(New SolidBrush(Color.Red), 40, 40, 140, 140) newBitmap.Save("c:\temp\TestImage.jpg", ImageFormat.Jpeg) |
||
C# | VB |
創建 Graphics 對象后,可以使用它繪制線、填充形狀、繪制文本等。與 Graphics 對象一起使用的主要對象如下所示。
Brush |
用于使用圖案、顏色或位圖填充封閉表面。 |
Pen |
用于繪制線和多邊形,包括矩形、弧線和扇形。 |
Font |
用于描述用來呈現文本的字體。 |
Color |
用于描述用來呈現特定對象的顏色。在 GDI+ 中,顏色可以是 Alpha 混合效果的。 |
Alpha 混合
顏色可以是 Alpha 混合的,這使得易于創建基于顏色疊加的效果。例如,下面的示例繪制一個紅色矩形,然后在不遮掩底層的紅色矩形的情況下疊加一個黃色矩形。
Dim g As Graphics = pe.Graphics g.FillRectangle(new SolidBrush(Color.Red), 600, 350, 100, 100) g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.Yellow)), 650, _ 400, 100, 100) |
||
C# | VB |
使用畫筆
使用畫筆填充形狀和路徑的內部。例如,若要創建紅色矩形,請參見下面的示例。
Dim g As Graphics = pe.Graphics g.FillRectangle(new SolidBrush(Color.Red), 600, 350, 100, 100) |
||
C# | VB |
畫筆可以是純色的、帶陰影的、帶紋理的或漸變的。陰影畫筆只不過是使用圖案進行繪畫的畫筆。
Dim g As Graphics = pe.Graphics HatchBrush hb = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Green, _ Color.FromArgb(100, Color.Yellow)) g.FillEllipse(hb, 250, 10, 100, 100) |
||
C# | VB |
帶紋理的畫筆使用位圖繪畫。例如,下面的代碼使用紋理畫筆繪制窗體的背景,然后對它應用白色"沖洗"以沖淡位圖中顏色的色調。
Dim g As Graphics = pe.Graphics Dim colorbars As Image = new Bitmap("colorbars.jpg") Dim backgroundBrush As Brush = new TextureBrush(colorbars) g.FillRectangle(backgroundBrush, ClientRectangle) g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), ClientRectangle) |
||
C# | VB |
LinearGradientBrush 使用兩種顏色繪畫。它根據在畫筆上設置的屬性填充給定的形狀,逐漸從一種顏色過渡到另一種顏色。例如,可以用下面所示代碼創建下列填充效果。
Dim r As Rectangle = new Rectangle(500, 300, 100, 100); Dim lb As LinearGradientBrush = new LinearGradientBrush(r, Color.Red, Color.Yellow, _ LinearGradientMode.BackwardDiagonal); e.Graphics.FillRectangle(lb, r); |
||
C# | VB |
PathGradient
畫筆允許創建更復雜的效果,如下列形狀。
它是用下面的代碼創建的。
Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased e.Graphics.FillRectangle(backgroundBrush, ClientRectangle) e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(180, Color.White)), ClientRectangle) Dim path As New GraphicsPath(New Point() { _ New Point(40, 140), _ New Point(275, 200), _ New Point(105, 225), _ new Point(190, 300), _ new Point(50, 350), _ new Point(20, 180), _ }, New Byte() { _ CType(PathPointType.Start, Byte), _ CType(PathPointType.Bezier, Byte), _ CType(PathPointType.Bezier, Byte), _ CType(PathPointType.Bezier, Byte), _ CType(PathPointType.Line, Byte), _ CType(PathPointType.Line, Byte), _ }) Dim pgb As New PathGradientBrush(path) pgb.SurroundColors = new Color() { _ Color.Green, _ Color.Yellow, _ Color.Red, _ Color.Blue, _ Color.Orange, _ Color.White, _ } e.Graphics.FillPath(pgb, path) End Sub |
||
C# | VB |
<nobr><a target="_top"><img src="http://chs.gotdotnet.com/quickstart/winforms/images/wflink.jpg" border="1" alt=""><br></a> <table><tbody><tr> <td class="caption">VB 畫筆示例</td> </tr></tbody></table> <br>[<a target="_top">運行示例</a>] | [<a target="_blank">查看源代碼</a>] </nobr> |
使用鋼筆
使用鋼筆繪制直線和曲線。可以設置屬性,如 PenType 、 DashStyle 、 Width 、 Color 和 EndCap ,以控制 Pen 如何進行繪制。
下面的代碼繪制一條曲線。
Dim g As Graphics ' Create a pen 20 pixels wide that is and purple and partially transparent. Dim penExample As New Pen(Color.FromArgb(150, Color.Purple), 20) ' Make it a dashed pen. Dim penExample.DashStyle As Pen = DashStyle.Dash ' Make the ends round. Dim penExample.StartCap As Pen = LineCap.Round Dim penExample.EndCap As Pen= LineCap.Round ' Now draw a curve using the pen g.DrawCurve(penExample, New Point() { _ New Point(200, 140), _ New Point(700, 240), _ New Point(500, 340), _ New Point(140, 140), _ New Point(40, 340), _ }) |
||
C# | VB |
還可以使用帶紋理的畫筆將紋理用作鋼筆的填充效果。
Dim g As Graphics Dim textureBrush As New TextureBrush(New Bitmap("Boiling Point.jpg")) Dim penExample As New Pen(textureBrush, 25) penExample.DashStyle = DashStyle.DashDotDot penExample.StartCap = LineCap.Triangle penExample.EndCap = LineCap.Round g.DrawLine(penExample, 10,450,550,400) |
||
C# | VB |
<nobr><a target="_top"><img src="http://chs.gotdotnet.com/quickstart/winforms/images/wflink.jpg" border="1" alt=""><br></a> <table><tbody><tr> <td class="caption">VB 筆示例</td> </tr></tbody></table> <br>[<a target="_top">運行示例</a>] | [<a target="_blank">查看源代碼</a>] </nobr> |
繪制文本
Graphics 對象的 DrawString 方法在繪圖表面上呈現文本。將要使用的字體和顏色傳遞給 DrawString 方法。例如,下面的代碼使用窗體的字體和黑色畫筆顯示文本"Hello World"。
Protected Overrides Sub OnPaint(e As PaintEventArgs) Dim g As Graphics = e.Graphics e.Graphics.FillRectangle(New SolidBrush(Color.White), ClientRectangle) g.DrawString("Hello World", Me.Font, New SolidBrush(Color.Black), 10,10) End Sub |
||
C# | VB |
因為 DrawString 采用畫筆,所以可以使用任何畫筆呈現文本。其中包括紋理畫筆。例如,下面的代碼呈現具有大理石效果和背景陰影的文本。
Protected Overrides Sub OnPaint(e As PaintEventArgs) Dim titleBrush As New TextureBrush(New Bitmap("marble.jpg")) Dim backgroundBrush As New TextureBrush(New Bitmap("colorbars.jpg")) Dim titleShadowBrush As New SolidBrush(Color.FromArgb(70, Color.Black)) Dim titleFont As New Font("Lucida Sans Unicode", 60) Dim titleText As String = "Graphics Samples" e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased e.Graphics.FillRectangle(backgroundBrush, ClientRectangle) e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(180, Color.White)), ClientRectangle) e.Graphics.DrawString(titleText, titleFont, titleShadowBrush, 15, 15) e.Graphics.DrawString(titleText, titleFont, titleBrush, 10, 10) End Sub |
||
C# | VB |
如果提供帶有 Rectangle 的 DrawString ,則文本將換行以適合該矩形。
Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased e.Graphics.FillRectangle(New SolidBrush(Color.White), ClientRectangle) Dim textFont As New Font("Lucida Sans Unicode", 12) Dim rectangle As New RectangleF(100, 100, 250, 350) e.Graphics.FillRectangle(New SolidBrush(Color.Gainsboro), rectangle) Dim flowedText As String ="Simplicity and power: Windows Forms is a programming model for" & ControlChars.CrLf _ & "developing Windows applications that combines the simplicity of the Visual" & ControlChars.CrLf _ & "Basic 6.0 programming model with the power and flexibility of the common" & ControlChars.CrLf _ & "language runtime." & ControlChars.CrLf _ & "Lower total cost of ownership: Windows Forms takes advantage of the versioning and" & ControlChars.CrLf _ & "deployment features of the common language runtime to offer reduced deployment" & ControlChars.CrLf _ & "costs and higher application robustness over time. This significantly lowers the" & ControlChars.CrLf _ & "maintenance costs (TCO) for applications" & ControlChars.CrLf _ & "written in Windows Forms." & ControlChars.CrLf _ & "Architecture for controls: Windows Forms offers an architecture for" & ControlChars.CrLf _ & "controls and control containers that is based on concrete implementation of the" & ControlChars.CrLf _ & "control and container classes. This significantly reduces" & ControlChars.CrLf _ & "control-container interoperability issues." & ControlChars.CrLf e.Graphics.DrawString(flowedText, textFont, New SolidBrush(Color.Blue), rectangle) End Sub |
||
C# | VB |
可以使用 StringFormat 對象控制如何繪制文本。例如,下面的代碼使您得以繪制在特定區域內居中的文本。
Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased e.Graphics.FillRectangle(New SolidBrush(Color.White), ClientRectangle) Dim textFont As New Font("Lucida Sans Unicode", 8) Dim rectangle As New RectangleF(100, 100, 250, 350) e.Graphics.FillRectangle(new SolidBrush(Color.Gainsboro), rectangle) Dim format As New StringFormat() format.Alignment = StringAlignment.Center Dim flowedText As String ="Simplicity and power: Windows Forms is a programming model for" & ControlChars.CrLf _ & "developing Windows applications that combines the simplicity of the Visual" & ControlChars.CrLf _ & "Basic 6.0 programming model with the power and flexibility of the common" & ControlChars.CrLf _ & "language runtime." & ControlChars.CrLf _ & "Lower total cost of ownership: Windows Forms takes advantage of the versioning and" & ControlChars.CrLf _ & "deployment features of the common language runtime to offer reduced deployment" & ControlChars.CrLf _ & "costs and higher application robustness over time. This significantly lowers the" & ControlChars.CrLf _ & "maintenance costs (TCO) for applications" & ControlChars.CrLf _ & "written in Windows Forms." & ControlChars.CrLf _ & "Architecture for controls: Windows Forms offers an architecture for" & ControlChars.CrLf _ & "controls and control containers that is based on concrete implementation of the" & ControlChars.CrLf _ & "control and container classes. This significantly reduces" & ControlChars.CrLf _ & "control-container interoperability issues." & ControlChars.CrLf e.Graphics.DrawString(flowedText, textFont, New SolidBrush(Color.Blue), rectangle,format) End Sub |
||
C# | VB |
如果要在繪制字符串時確定該字符串的長度,可使用 MeasureString 。例如,若要將某個字符串在窗體上居中顯示,請使用下面的代碼。
Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased e.Graphics.FillRectangle(new SolidBrush(Color.White), ClientRectangle) Dim textToDraw As String ="Hello Symetrical World" Dim textFont As New Font("Lucida Sans Unicode", 8) Dim windowCenter As Double = this.DisplayRectangle.Width/2 Dim stringSize As SizeF = e.Graphics.MeasureString(textToDraw, textFont) Dim startPos As Double = windowCenter-(stringSize.Width/2) e.Graphics.DrawString(textToDraw, textFont, new SolidBrush(Color.Blue), startPos, 40) End Sub |
||
C# | VB |
MeasureString 還可用于確定呈現多少行和多少個字符。例如,我們可以確定在上一個討論過的文本示例中呈現多少行和多少個字符。
Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased e.Graphics.FillRectangle(new SolidBrush(Color.White), ClientRectangle) Dim textFont As New Font("Lucida Sans Unicode", 12) Dim rectangle As New RectangleF(100, 100, 250, 350) Dim lines As Integer Dim characters As Integer Dim flowedText As String ="Simplicity and power: Windows Forms is a programming model for" & ControlChars.CrLf _ & "developing Windows applications that combines the simplicity of the Visual" & ControlChars.CrLf _ & "Basic 6.0 programming model with the power and flexibility of the common" & ControlChars.CrLf _ & "language runtime." & ControlChars.CrLf _ & "Lower total cost of ownership: Windows Forms takes advantage of the versioning and" & ControlChars.CrLf _ & "deployment features of the common language runtime to offer reduced deployment" & ControlChars.CrLf _ & "costs and higher application robustness over time. This significantly lowers the" & ControlChars.CrLf _ & "maintenance costs (TCO) for applications" & ControlChars.CrLf _ & "written in Windows Forms." & ControlChars.CrLf _ & "Architecture for controls: Windows Forms offers an architecture for" & ControlChars.CrLf _ & "controls and control containers that is based on concrete implementation of the" & ControlChars.CrLf _ & "control and container classes. This significantly reduces" & ControlChars.CrLf _ & "control-container interoperability issues." & ControlChars.CrLf Dim whatRenderedText As String e.Graphics.FillRectangle(New SolidBrush(Color.Gainsboro), rectangle) e.Graphics.MeasureString(flowedText, textFont, rectangle.Size, _ new StringFormat(), characters, lines) whatRenderedText = "We printed " & characters & " characters and " & lines & " lines" e.Graphics.DrawString(flowedText, textFont, New SolidBrush(Color.Blue), rectangle) e.Graphics.DrawString(whatRenderedText, Me.Font, New SolidBrush(Color.Black), 10,10) End Sub |
||
C# | VB |
GDI+ 完全支持 Unicode。這意味著可以用任何語言呈現文本。例如,下面的代碼用日語繪制字符串(必須安裝有日語語言包)。
Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased e.Graphics.FillRectangle(new SolidBrush(Color.White), ClientRectangle) Try Dim japaneseFont As New Font("MS Mincho", 32) Dim japaneseText As New String(new char() {CType(31169, Char), CType(12398, Char), _ CType(21517, Char), CType(21069, Char), CType(12399, Char), _ CType(12463, Char), CType(12522, Char), CType(12473, Char), _ CType(12391, Char), CType(12377, Char), CType(12290, Char)}) e.Graphics.DrawString(japaneseText, japaneseFont, new SolidBrush(Color.Blue), 20, 40) Catch ex As Exception MessageBox.Show("You need to install the Japanese language pack to run this sample") Application.Exit() End Try End Sub |
||
C# | VB |
<nobr><a target="_top"><img src="http://chs.gotdotnet.com/quickstart/winforms/images/wflink.jpg" border="1" alt=""><br></a> <table><tbody><tr> <td class="caption">VB 文本示例</td> </tr></tbody></table> <br>[<a target="_top">運行示例</a>] | [<a target="_blank">查看源代碼</a>] </nobr> |
使用圖像
GDI+ 完全支持各種圖像格式,包括 .jpeg、.png、.gif、.bmp、.tiff、.exif 和 .icon 文件。
呈現圖像非常簡單。例如,下面的代碼呈現一個 .jpeg 圖像。
Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.FillRectangle(New SolidBrush(Color.White), ClientRectangle) e.Graphics.DrawImage(New Bitmap("sample.jpg"), 29, 20, 283, 212) End Sub |
||
C# | VB |
使用位圖作為呈現圖面也非常簡單。下面的代碼將一些文本和線呈現到位圖上,然后將該位圖作為 .png 文件保存到磁盤中。
Dim newBitmap As New Bitmap(800,600,PixelFormat.Format32bppArgb) Dim g As Graphics = Graphics.FromImage(newBitmap) g.FillRectangle(New SolidBrush(Color.White), new Rectangle(0,0,800,600)) Dim textFont As New Font("Lucida Sans Unicode", 12) Dim rectangle As New RectangleF(100, 100, 250, 350) Dim Lines As Integer Dim Characters As Integer Dim flowedText As String ="Simplicity and power: Windows Forms is a programming model for" & ControlChars.CrLf _ & "developing Windows applications that combines the simplicity of the Visual" & ControlChars.CrLf _ & "Basic 6.0 programming model with the power and flexibility of the common" & ControlChars.CrLf _ & "language runtime." & ControlChars.CrLf _ & "Lower total cost of ownership: Windows Forms takes advantage of the versioning and" & ControlChars.CrLf _ & "deployment features of the common language runtime to offer reduced deployment" & ControlChars.CrLf _ & "costs and higher application robustness over time. This significantly lowers the" & ControlChars.CrLf _ & "maintenance costs (TCO) for applications" & ControlChars.CrLf _ & "written in Windows Forms." & ControlChars.CrLf _ & "Architecture for controls: Windows Forms offers an architecture for" & ControlChars.CrLf _ & "controls and control containers that is based on concrete implementation of the" & ControlChars.CrLf _ & "control and container classes. This significantly reduces" & ControlChars.CrLf _ & "control-container interoperability issues." & ControlChars.CrLf g.FillRectangle(new SolidBrush(Color.Gainsboro), rectangle) g.DrawString(flowedText, textFont, new SolidBrush(Color.Blue), rectangle) Dim penExample As New Pen(Color.FromArgb(150, Color.Purple), 20) penExample.DashStyle = DashStyle.Dash penExample.StartCap = LineCap.Round penExample.EndCap = LineCap.Round g.DrawCurve(penExample, new Point() { _ new Point(200, 140), _ new Point(700, 240), _ new Point(500, 340), _ new Point(140, 140), _ new Point(40, 340), _ }) newBitmap.Save("TestImage.png", ImageFormat.Png) |
||
C# | VB |
<nobr><a target="_top"><img src="http://chs.gotdotnet.com/quickstart/winforms/images/wflink.jpg" border="1" alt=""><br></a> <table><tbody><tr> <td class="caption">VB 圖像示例</td> </tr></tbody></table> <br>[<a target="_top">運行示例</a>] | [<a target="_blank">查看源代碼</a>] </nobr> |
其他信息
標準鋼筆和畫筆
Pen 和 Brush 類包括一組用于所有已知顏色的標準純色鋼筆和畫筆。
消除鋸齒
將 Graphics.SmoothingMode 設置為 SmoothingMode.AntiAlias 將導致更銳化的文本和圖形。圖形對象的范圍
Paint 事件的參數 ( PaintEventArgs ) 中包含的圖形對象根據 Paint 事件處理程序的返回結果進行處置。因此,不應保持對范圍超出 Paint 事件之外的此 Graphics 對象的引用。嘗試在 Paint 事件之外使用此 Graphics 對象將出現不可預知的結果。處理調整大小
默認情況下,當調整控件或窗體大小時不引發 Paint 事件。如果希望在調整窗體大小時引發 Paint 事件,則需要相應地設置控件樣式。
Public Sub MyForm() SetStyle(ControlStyles.ResizeRedraw,True) End Sub |
||
C# | VB |
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
