項目中要用圖形來顯示一個閥門的開度,以及控制閥的開度。本來是要用什么公司買的控件中的餅圖之類的實現(xiàn),不過我覺得也是麻煩,就想,還是自己畫吧。
超過十年行業(yè)經(jīng)驗,技術領先,服務至上的經(jīng)營模式,全靠網(wǎng)絡和口碑獲得客戶,為自己降低成本,也就是為客戶降低成本。到目前業(yè)務范圍包括了:成都網(wǎng)站設計、做網(wǎng)站,成都網(wǎng)站推廣,成都網(wǎng)站優(yōu)化,整體網(wǎng)絡托管,小程序設計,微信開發(fā),成都app軟件開發(fā)公司,同時也可以讓客戶的網(wǎng)站和網(wǎng)絡營銷和我們一樣獲得訂單和生意!
首先添加一個TrackBar,名字是“TrackBar1”,一個label,名字是“L_A_SHANG”,一個GroupBox,名字是“GB_RIGHT”,,然后添加拉動滾動條時的處理函數(shù)
'上位機控制
Dim m_start As Integer
Dim RcDraw As System.Drawing.Rectangle
Private Sub TrackBar1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
m_start = (100 - TrackBar1.Value)
Me.L_A_SHANG.Text = Me.TrackBar1.Value.ToString
GB_RIGHT.Invalidate() '重畫GB_RIGHT
End Sub
添加GB_RIGHT重畫時的處理函數(shù)
Private Sub GB_RIGHT_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GB_RIGHT.Paint
RcDraw.X = TrackBar1.Location.X - 40
RcDraw.Y = 20
RcDraw.Height = 100
RcDraw.Width = 20
e.Graphics.DrawRectangle(New Pen(Color.Blue, 5), RcDraw)
Dim i = TrackBar1.Location.X - 40
For i = TrackBar1.Location.X - 40 To TrackBar1.Location.X - 20
e.Graphics.DrawLine(New Pen(Color.Blue, 5), i, m_start + 20, i, 120)
Next
Me.L_A_SHANG.Text = Me.TrackBar1.Value.ToString + "%"
End Sub
到此以及可以實現(xiàn)拉動條的時候,圖像跟著變化,并顯示百分比。
代碼:
Public?Class?Form1
'*********************************************************************???
'作者:章魚哥,QQ:3107073263?群:309816713???????
'如有疑問或好的建議請聯(lián)系我,大家一起進步?????
'*********************************************************************?????
'繪制圓角矩形函數(shù)
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)
'清楚現(xiàn)有的矩形
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()?'此函數(shù)可引發(fā)Paint事件
End?Sub
End?Class
效果截圖:
原窗口:
縮小后:
VB.net與VB不同。
VB.net已經(jīng)有專門繪圖的類。
可以定義筆刷然后用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
。net ?其實還是很好繪制圖形的
你可以看下?Graphics ?類
Dim d As New Bitmap(Me.Width, Me.Height) ?‘一個圖片吧
? Dim g As Graphics = Graphics.FromImage(d)’繪制 ?準備在這個圖片是進行
然后 ?就是你繪制的東西了
線 就是 ??g.DrawLine()
圓 弧度 ?就用 ?g.DrawArc(Pens.Black, New Rectangle(0, 0, 400, 200), 0, 360)
復雜的就是 ? ? ?g.DrawBezier()
等 ?如果你用的是 VS的 ?編譯 ?上面都有詳細的參數(shù)說明
Dim?d?As?New?Bitmap(Me.Width,?Me.Height)
Dim?g?As?Graphics?=?Graphics.FromImage(d)
g.DrawArc(Pens.Black,?New?Rectangle(0,?0,?200,?200),?0,?360)
g.DrawLine(Pens.Red,?New?Point(0,?0),?New?Point(200,?200))
g.DrawLines(Pens.Green,?New?Point()?{New?Point(0,?0),?New?Point(50,?40),?New?Point(50,?80),?New?Point(90,?70),?New?Point(100,?400)})
g.DrawBezier(Pens.Yellow,?New?Point(0,?100),?New?Point(0,?0),?New?Point(200,?0),?New?Point(200,?200))
g.Dispose()
Me.BackgroundImage?=?d
新聞標題:vb.net如何繪圖 vb繪圖教程
網(wǎng)頁網(wǎng)址:http://chinadenli.net/article46/dodcceg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設計、動態(tài)網(wǎng)站、、電子商務、網(wǎng)站設計、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)