vbnet畫(huà)圖,vbnet菜鳥(niǎo)教程

vb.net 畫(huà)圖問(wèn)題

Public?Class?Form1

創(chuàng)新互聯(lián)建站-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比濟(jì)水街道網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式濟(jì)水街道網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋濟(jì)水街道地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴(lài)。

Public?myPen?As?New?System.Drawing.Pen(System.Drawing.Color.Red)

Public?formGraphics?As?System.Drawing.Graphics

Private?r?As?Integer?=?5?'點(diǎn)半徑

Private?data(10)?As?System.Drawing.Point?'數(shù)據(jù)點(diǎn)

Private?link(10,?10)?As?Integer

Private?Sub?Button1_Click(sender?As?Object,?e?As?EventArgs)?Handles?Button1.Click

For?Each?pt?In?data

formGraphics.DrawEllipse(myPen,?New?Rectangle(pt.X,?pt.Y,?r,?r))

Next

DrawLink(data)

End?Sub

Private?Sub?DrawLink(data()?As?System.Drawing.Point)

Dim?pt1,?pt2?As?System.Drawing.Point

For?i?=?0?To?UBound(link)

For?j?=?0?To?UBound(link,?2)?-?i?-?1

If?link(i,?j)?=?1?Then

pt1.X?=?data(i).X?+?r?/?2?:?pt1.Y?=?data(i).Y?+?r?/?2

pt2.X?=?data(j).X?+?r?/?2?:?pt2.Y?=?data(j).Y?+?r?/?2

formGraphics.DrawLine(myPen,?pt1,?pt2)

End?If

Next?j

Next?i

End?Sub

Private?Sub?Form1_Load(sender?As?Object,?e?As?EventArgs)?Handles?MyBase.Load

Dim?i,?j?As?Integer

formGraphics?=?GroupBox1.CreateGraphics()

r?=?10

'生成一些測(cè)試數(shù)據(jù)

Randomize()

For?i?=?0?To?UBound(data)

data(i).x?=?Rnd()?*?400

data(i).y?=?Rnd()?*?200

Next

'生成一些測(cè)試邊

For?i?=?0?To?UBound(link)

For?j?=?0?To?UBound(link,?2)?-?i?-?1

link(i,?j)?=?Int(Rnd()?*?2)

Next?j

Next?i

End?Sub

Private?Sub?Form1_FormClosed(sender?As?Object,?e?As?FormClosedEventArgs)?Handles?MyBase.FormClosed

myPen.Dispose()

formGraphics.Dispose()

End?Sub

End?Class

VB.net中如何畫(huà)圖?

VB.net與VB不同。

VB.net已經(jīng)有專(zhuān)門(mén)繪圖的類(lèi)。

可以定義筆刷然后用Drawing類(lèi)中的方法繪制。

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 畫(huà)圖對(duì)象問(wèn)題

參考一下下面這段代碼:

‘?首先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畫(huà)圖而不清空原圖像

'?建立一個(gè)畫(huà)圖對(duì)象

Dim?g?As?Graphics?=?Me.PictureBox1.CreateGraphics

‘?定義畫(huà)筆

Dim?myPen?As?System.Drawing.Pen?=?New?System.Drawing.Pen(Color.Blue)

’?畫(huà)出矩形框并且填充顏色(顏色保持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))

'?最后釋放畫(huà)圖對(duì)象

g.Dispose()

效果大致如下圖所示:

vb.net 畫(huà)圖 如何保持圖形

不用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)?????'定義紅色畫(huà)筆??

Dim?penblue?As?Pen?=?New?Pen(Color.Blue,?1)?'定義藍(lán)色畫(huà)筆?

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

本文標(biāo)題:vbnet畫(huà)圖,vbnet菜鳥(niǎo)教程
網(wǎng)頁(yè)路徑:http://muchs.cn/article48/phjdhp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、企業(yè)網(wǎng)站制作服務(wù)器托管、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)