創(chuàng)建Graphics對(duì)象,可以調(diào)用CreateGraphics()直接做圖也可以創(chuàng)建Bitmap對(duì)象然后調(diào)用Graphics.FromBitmap(b)得到Graphics G
目前創(chuàng)新互聯(lián)已為上1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站托管運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、冀州網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
G.Clear(Colors.Black)
G.DrawLine(Pens.White, 畫線的坐標(biāo)
自己用GDI+畫的 無(wú)論什么什么尺寸的picturebox都行
不過(guò)別太小了o(∩_∩)o
代碼放在哪里自己決定啊
最好是放在 picturebox的resize時(shí)間里
每次picturebox大小改變都重畫一次坐標(biāo)
Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim g As Graphics = Graphics.FromImage(b)
g.Clear(Color.White)
Dim p As New Pen(Color.Black)
p.EndCap = Drawing2D.LineCap.ArrowAnchor
g.DrawLine(p, 30, PictureBox1.Height - 30, 30, 30)
g.DrawLine(p, 30, PictureBox1.Height - 30, PictureBox1.Width - 30, PictureBox1.Height - 30)
Dim i As Integer
Dim bs As New SolidBrush(Color.Green)
Dim po As New Point
po.X = 0
po.Y = PictureBox1.Height - 35
For i = 700 To 1000 Step 50
g.DrawString(i, Me.Font, bs, po.X, po.Y)
g.DrawLine(p, po.X + 28, po.Y + 5, po.X + 30, po.Y + 5)
po.Y -= (PictureBox1.Height - 100) / 6
Next
po.X = 30
po.Y = PictureBox1.Height - 30
For i = 0 To 40 Step 5
g.DrawString(i, Me.Font, bs, po.X, po.Y + 5)
g.DrawLine(p, po.X, po.Y + 2, po.X, po.Y)
po.X += (PictureBox1.Width - 100) / 8
Next
PictureBox1.Image = b
scale(x1,y1)-(x2,y2)
你只要記住,這里的x1,y1是左上角的坐標(biāo),x2,y2是右下角的坐標(biāo),通過(guò)這兩個(gè)點(diǎn)的坐標(biāo)設(shè)定,就可以決定坐標(biāo)原點(diǎn)的位置以及坐標(biāo)軸的方向了,比如
Scale (-300,200)-(300,-200)
以上是把坐標(biāo)原點(diǎn)設(shè)在窗體中心,x軸長(zhǎng)600,方向從左到右,y軸長(zhǎng)400,方向從下向上。
Scale (800,0)-(0,600)
以上是把坐標(biāo)原點(diǎn)設(shè)在窗體右上角,x軸長(zhǎng)800,方向從右到左,y軸長(zhǎng)600,方向從上向下。
下面說(shuō)坐標(biāo)軸和原點(diǎn)的標(biāo)示法:
假定自定義坐標(biāo)設(shè)為:
Scale (-300, 200)-(300, -200)
則
Line (-300, 0)-(300, 0) '畫x軸
Line (0, 200)-(0, -200) '畫y軸
CurrentX = 290
CurrentY = -5
Print "x" '標(biāo)示x軸
CurrentX = 5
CurrentY = 200
Print "y" '標(biāo)示y軸
CurrentX = 5
CurrentY = -5
Print "0" '標(biāo)示原點(diǎn)
Dim g As Graphics = PictureBox1.CreateGraphics
g.TranslateTransform(2, 2) ‘定義原點(diǎn)坐標(biāo)
g.ScaleTransform(1, -1) ’X軸不變,反轉(zhuǎn)Y軸
以PictureBox1中(2,2)點(diǎn)為新的原點(diǎn)(0,0)
向右為X軸正方向 向上為Y軸正方向