vb.net画图工具,vb绘图控件

VB.net中如何画图?

VB.net与VB不同。

创新互联主营宁江网站建设的网络公司,主营网站建设方案,重庆APP软件开发,宁江h5微信小程序开发搭建,宁江网站营销推广欢迎宁江等地区企业咨询

VB.net已经有专门绘图的类。

可以定义笔刷然后用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 绘图,重绘知识

继承(Inherits)控件就可以重写它的属性和方法,图标可以在paint中重绘,用gdi,工具主要在drawing和drawing2d中。

combobox弹出的框增加图标吗?个人看法可能需要得到那个句柄,才可以重绘,但那个好像是一体的,不知道能不能弄到句柄。

textbox可以自定义高度。只是以行高度为单位,改变字体大小即可,没必要重写吧。

我也自学,感觉基础容易学,进阶资料少。循序渐进也没序可循,基本是在摸索。

都是想到什么问题,就立下一个目标,然后攻破他,结果可能是尝试几天后,发现目标超出能力范围。

晦涩是相对的,实践出真知,多动手,基础就好了。

VB.NET 画图工具代码

Imports System

Imports System.IO

Public Class Form2

Private mBmpBuffer As Bitmap

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

mBmpBuffer = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height, Me.PictureBox1.CreateGraphics) Dim g As Graphics = Graphics.FromImage(mBmpBuffer)

Dim i As Integer

Dim aa(3, 1) As Single

Dim stra() As String

Try

Dim sr As StreamReader = New StreamReader("D:\模型相关\modeldesign\modelpaint\data.csv")

Dim line As String

Do

line = sr.ReadLine() i = i + 1

If i 1 Then

stra = Split(line, ";")

aa(i - 2, 0) = Val(stra(0))

aa(i - 2, 1) = Val(stra(1))

End If Loop Until line Is Nothing

sr.Close()

Catch ex As Exception End Try Dim ix As Single

Dim iy As Single

Dim temp As Single temp = aa(0, 0)

For i = 0 To 3

If aa(i, 0) temp Then

temp = aa(i, 0)

End If

Next

ix = temp temp = aa(0, 1)

For i = 0 To 3

If aa(i, 1) temp Then

temp = aa(i, 1)

End If

Next

iy = temp

'变换坐标

Dim bx As Single

Dim by As Single bx = PictureBox1.Width / ix

by = PictureBox1.Height / iy 'Dim g As Graphics = Me.PictureBox1.CreateGraphics

g.Clear(Color.White)

Dim mypoint(3) As Point

Dim n As Integer = 3

'变换坐标原点

g.TranslateTransform(PictureBox1.Width / 15, PictureBox1.Height * 14 / 15)

'g.ScaleTransform(PictureBox1.Width / ix, PictureBox1.Height / iy) '绘制坐标轴

Dim mypen As New Pen(Color.Black)

Dim sb As New SolidBrush(Color.Black)

'Dim sb1 As Brush = Brushes.Red

Dim mypen1 As New Pen(Color.Blue, 6)

g.DrawLine(mypen, 0, 0, PictureBox1.Width - 40, 0)

g.DrawLine(mypen, 0, 0, 0, 20 - PictureBox1.Height)

For i = 0 To PictureBox1.Width - 40 Step 40

g.DrawLine(mypen, i, 0, i, -10)

g.DrawString(Int(i / 0.9 / bx), New Font("宋体", 8), sb, i - 10, 0)

Next

g.DrawString("C", New Font("宋体", 8), sb, PictureBox1.Width - 50, 0) For i = 40 To PictureBox1.Height - 40 Step 40

g.DrawLine(mypen, 0, -i, 10, -i)

g.DrawString(Int(i / 0.9 / by), New Font("宋体", 8), sb, -20, -i - 10)

Next

g.DrawString("x", New Font("宋体", 8), sb, -10, 20 - PictureBox1.Height)

'mypen.Width = 1

g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

For i = 0 To n

mypoint(i).X = aa(i, 0) * bx * 0.9

mypoint(i).Y = -aa(i, 1) * by * 0.9

'g.FillRectangle(sb1, mypoint(i).X, mypoint(i).Y, 3, mypoint(i).Y)

g.DrawLine(mypen1, mypoint(i).X, 0, mypoint(i).X, mypoint(i).Y)

Next '开始画线

'g.DrawCurve(mypen, mypoint)

Me.PictureBox1.Refresh()

End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim strFilter As String = "BMP文件(*.bmp)|*.bmp"

Dim pdlg As SaveFileDialog = New SaveFileDialog

pdlg.Title = "地图另存为"

pdlg.Filter = strFilter

pdlg.OverwritePrompt = True

pdlg.ShowDialog() If Not pdlg.FileName.Equals("") Then

If Not (mBmpBuffer Is Nothing) Then

'mBmpBuffer.Save("c:\a.bmp")

mBmpBuffer.Save(pdlg.FileName)

End If End If

End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

If Not (mBmpBuffer Is Nothing) Then

e.Graphics.DrawImage(mBmpBuffer, 0, 0)

End If

End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

ComboBox1.Items.Clear()

ComboBox1.Items.Add("模型一")

ComboBox1.Items.Add("模型二")

ComboBox1.Items.Add("模型三")

ComboBox1.Text = "模型一"

End Sub

End Class

发表于 @ 2007年10月31日 11:53:00 | 评论( 0 ) | 编辑| 举报| 收藏 旧一篇:SharpMap AjaxMapControl 中 Zoomin/Zoomout 操作时冻结问题 | 新一篇:Windows 窗体控件进行线程安全调用

本文来自CSDN博客,转载请标明出处:

VB.Net如何实现抠图并绘图

项目中要用图形来显示一个阀门的开度,以及控制阀的开度。本来是要用什么公司买的控件中的饼图之类的实现,不过我觉得也是麻烦,就想,还是自己画吧。

首先添加一个TrackBar,名字是“TrackBar1”,一个label,名字是“L_A_SHANG”,一个GroupBox,名字是“GB_RIGHT”,,然后添加拉动滚动条时的处理函数

'上位机控制

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重画时的处理函数

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

到此以及可以实现拉动条的时候,图像跟着变化,并显示百分比。


分享名称:vb.net画图工具,vb绘图控件
网页链接:http://ybzwz.com/article/dscspsi.html