項目中要用圖形來顯示一個閥門的開度,以及控制閥的開度。本來是要用什么公司買的控件中的餅圖之類的實現(xiàn),不過我覺得也是麻煩,就想,還是自己畫吧。
創(chuàng)新互聯(lián)建站服務項目包括廣豐網(wǎng)站建設、廣豐網(wǎng)站制作、廣豐網(wǎng)頁制作以及廣豐網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網(wǎng)行業(yè)的解決方案,廣豐網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到廣豐省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!
首先添加一個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)拉動條的時候,圖像跟著變化,并顯示百分比。
您好,您是想問vb.net連續(xù)繪制曲線圖不消失怎么辦?b.net連續(xù)繪制曲線圖不消失的解決辦法如下:
1、首先必須創(chuàng)建bitmap,關聯(lián)到picturebox1.image上。
2、再在picturebox1.image上創(chuàng)建Graphics,再進行作圖。即可顯示線圖。
代碼:
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
文章題目:vb.net繪圖相關 vb 繪圖
當前鏈接:http://m.rwnh.cn/article46/hiieeg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、網(wǎng)站維護、網(wǎng)站營銷、網(wǎng)站收錄、網(wǎng)站設計、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)