VB點虐 與VB不同。
創(chuàng)新互聯(lián)公司公司2013年成立,先為寧城等服務建站,寧城等地企業(yè),進行企業(yè)商務咨詢服務。為寧城企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。
VB點虐 已經有專門繪圖的類。
可以定義筆刷然后用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點虐 里有個很簡單的辦法,就是把Form1的TransparencyKey 屬性設置成白色,你的圖片的白色就會變成透明的了,很方便吧。
項目中要用圖形來顯示一個閥門的開度,以及控制閥的開度。本來是要用什么公司買的控件中的餅圖之類的實現(xiàn),不過我覺得也是麻煩,就想,還是自己畫吧。
首先添加一個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)拉動條的時候,圖像跟著變化,并顯示百分比。
你去查查書吧,書上挺詳細的,在這說不好說,你先在項目里引用。然后 Dim acadapp As AcadApplication Dim acaddoc As AcadDocument On Error Resume Next AcadApp = GetObject(, "AutoCAD.Application") If Err.Number Then Err.Clear() AcadApp = CreateObject("AutoCAD.Application") If Err.Number Then MsgBox("不能運行AutoCAD,請檢查是否安裝了AutoCAD") Exit Sub End If End If AcadApp.Visible = True '界面可視