Private Function isopen() As AutoCAD.AcadApplication
創(chuàng)新互聯(lián)一直通過(guò)網(wǎng)站建設(shè)和網(wǎng)站營(yíng)銷幫助企業(yè)獲得更多客戶資源。 以"深度挖掘,量身打造,注重實(shí)效"的一站式服務(wù),以成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、移動(dòng)互聯(lián)產(chǎn)品、全網(wǎng)營(yíng)銷推廣服務(wù)為核心業(yè)務(wù)。十多年網(wǎng)站制作的經(jīng)驗(yàn),使用新網(wǎng)站建設(shè)技術(shù),全新開(kāi)發(fā)出的標(biāo)準(zhǔn)網(wǎng)站,不但價(jià)格便宜而且實(shí)用、靈活,特別適合中小公司網(wǎng)站制作。網(wǎng)站管理系統(tǒng)簡(jiǎn)單易用,維護(hù)方便,您可以完全操作網(wǎng)站資料,是中小公司快速網(wǎng)站建設(shè)的選擇。
Try
dim CADapp_temp AutoCAD.AcadApplication = GetObject(, "AutoCAD.Application")
return CADapp_temp
Catch ex As Exception
Return Nothing
End Try
End Function
'調(diào)用上面的函數(shù),如果為nothing表示沒(méi)有打開(kāi),否則打開(kāi)并返回對(duì)象
不用PictureBoxTest.Image屬性,直接把圖形繪制到PictureBoxTest上面就可以了。
Dim?button?As?Integer?=?0
Private?Sub?Button1_Click(ByVal?sender?As?Object,?ByVal?e?As?EventArgs)?_
Handles?Button1.Click
Using?g?As?Graphics?=?Graphics.FromHwnd(PictureBoxTest.Handle)
Dim?penRed?As?Pen?=?New?Pen(Color.Red,?1)?????'定義紅色畫筆??
Dim?penblue?As?Pen?=?New?Pen(Color.Blue,?1)?'定義藍(lán)色畫筆?
If?button?=?0?Then
g.DrawLine(penRed,?0,?0,?100,?100)
button?=?1
ElseIf?button?=?1?Then
g.DrawLine(penblue,?100,?100,?200,?200)
button?=?0
End?If
End?Using
End?Sub
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
Imports System.Drawing.Imaging
Public Class Form1
Dim imageName As String = "C:\Documents and Settings\...\1126.jpg "
Dim i As Image = Image.FromFile(imageName)
Dim g As Graphics = Graphics.FromImage(i) '此處從背景圖創(chuàng)建Greaphics
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'劃線
Dim BluePen As New Pen(Color.Blue, 5)
BluePen.DashStyle = Drawing2D.DashStyle.Solid
g.DrawLine(BluePen, 100.0F, 170, 500.0F, 170)
g.Dispose()
PictureBox1.Image = i
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'退出
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'存盤
i.Save( "C:\testimage.jpg ", ImageFormat.Jpeg)
i.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PictureBox1.Image = i
End Sub
End Class
參考一下下面這段代碼:
‘?首先picturebox1?加載一張圖像
FolderBrowserDialog1.Description?=?"選擇圖片文件夾導(dǎo)入圖片"
FolderBrowserDialog1.ShowDialog()
path?=?FolderBrowserDialog1.SelectedPath()
If?path?=?""?Then?Return
strSrcFile?=?Dir(path??"\*.tif")
PictureBox1.Image?=?Image.FromFile(path??"\"??strSrcFile)
’??然后再在picturebox1中用graphic畫圖而不清空原圖像
'?建立一個(gè)畫圖對(duì)象
Dim?g?As?Graphics?=?Me.PictureBox1.CreateGraphics
‘?定義畫筆
Dim?myPen?As?System.Drawing.Pen?=?New?System.Drawing.Pen(Color.Blue)
’?畫出矩形框并且填充顏色(顏色保持50%的透明度,使得下面原來(lái)的圖片背景能看得到)
g.DrawRectangle(myPen,?New?System.Drawing.Rectangle(50,?50,?30,?20))
g.FillRectangle(New?SolidBrush(Color.FromArgb(50,?Color.YellowGreen)),?New?System.Drawing.Rectangle(50,?50,?30,?20))
'?最后釋放畫圖對(duì)象
g.Dispose()
效果大致如下圖所示: