代碼:
創(chuàng)新互聯自2013年起,是專業(yè)互聯網技術服務公司,擁有項目成都網站設計、網站制作網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元太平做網站,已為上家服務,為太平各地企業(yè)和個人服務,聯系電話:028-86922220
Public?Class?Form1
'*********************************************************************???
'作者:章魚哥,QQ:3107073263?群:309816713???????
'如有疑問或好的建議請聯系我,大家一起進步?????
'*********************************************************************?????
'繪制圓角矩形函數
Private?Function?GetRoundedRectPath(ByVal?rect?As?Rectangle,?ByVal?radius?As?Integer)?As?System.Drawing.Drawing2D.GraphicsPath
rect.Offset(-1,?-1)
Dim?RoundRect?As?New?Rectangle(rect.Location,?New?Size(radius?-?1,?radius?-?1))
Dim?path?As?New?System.Drawing.Drawing2D.GraphicsPath
path.AddArc(RoundRect,?180,?90)?????'左上角
RoundRect.X?=?rect.Right?-?radius???'右上角
path.AddArc(RoundRect,?270,?90)
RoundRect.Y?=?rect.Bottom?-?radius??'右下角
path.AddArc(RoundRect,?0,?90)
RoundRect.X?=?rect.Left?????????????'左下角
path.AddArc(RoundRect,?90,?90)
path.CloseFigure()
Return?path
End?Function
'繪制矩形
Private?Sub?DrawingRect()
Dim?g?As?Graphics?=?Me.CreateGraphics
Dim?Pen?As?New?Pen(Brushes.DarkRed,?2)
Dim?Hei?As?Integer?=?Me.Height
Dim?Wid?As?Integer?=?Me.Width
'矩形的位置和長寬隨著窗體的變化而改變
Dim?Rec?As?New?Rectangle(Int(Wid?/?5),?Int(Hei?/?5),?Int(Wid?/?2),?Int(Hei?/?2))
'??g.DrawRectangle(Pen,?Rec)
'清楚現有的矩形
g.Clear(Me.BackColor)
g.DrawPath(Pen,?GetRoundedRectPath(Rec,?30))
End?Sub
Private?Sub?Form1_Paint(ByVal?sender?As?System.Object,?ByVal?e?As?System.Windows.Forms.PaintEventArgs)?Handles?MyBase.Paint
DrawingRect()
End?Sub
Private?Sub?Form1_SizeChanged(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?MyBase.SizeChanged
Me.Invalidate()?'此函數可引發(fā)Paint事件
End?Sub
End?Class
效果截圖:
原窗口:
縮小后:
下面的例子通過重載Form 窗體的OnPaint()方法繪制GDI圖形Protected Overrides Sub onpaint(ByVal e As System Windows Forms PaintEventArgs)注釋 /////////////繪制任意直線Dim g As Graphics = e GraphicsDim mypen As Pen = New Pen(Color Red )g DrawLine(mypen )注釋 /////////////繪制矩形(任意直線構成的封閉圖形)Dim point As PointF = New PointF( F F)Dim point As PointF = New PointF( F F)Dim point As PointF = New PointF( F F)Dim point As PointF = New PointF( F F)Dim curvepoints As PointF() = {point point point point }g DrawPolygon(New Pen(Color Blue ) curvepoints)注釋 ////////////文本表示Dim FFamily As FontFamily = New FontFamily( Arial )Dim font As Font = New Font(FFamily FontStyle Bold FontStyle Italic GraphicsUnit Pixel)Dim text As String = I love you! Dim solidbrush As SolidBrush = New SolidBrush(Color Red)Dim pr As PointF = New PointF( )e Graphics DrawString(text font solidbrush pr)注釋 ////////////平面繪制Dim rec As RectangleF = New RectangleF( )g DrawPie(mypen rec )注釋 ///////////封閉圖形 應該是個圓g DrawClosedCurve(mypen curvepoints Drawing Drawing D FillMode Alternate)注釋 ///////////大家自己試試看吧g DrawArc(mypen )g DrawCurve(mypen curvepoints)g DrawBezier(mypen )g DrawBeziers(mypen curvepoints)注釋 //////////這可是一個圓Dim rec As RectangleF = New RectangleF( )g DrawEllipse(mypen rec )注釋 //////////這是一個橢圓Dim rec As RectangleF = New RectangleF( )g DrawEllipse(mypen rec )End Sub 這些是我自己試驗出來的 當然了 還有好多 我只是開了一個頭 大家要是發(fā)現什么好東東 別忘了通知一下 ) lishixinzhi/Article/program/net/201311/11800
VB.net與VB不同。
VB.net已經有專門繪圖的類。
可以定義筆刷然后用Drawing類中的方法繪制。
Private Sub DrawEllipse()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Private Sub DrawRectangle()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawRectangle(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub