重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
不用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) '定义蓝色画笔
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
分类: 电脑/网络 程序设计 其他编程语言
问题描述:
VB6中的form1.circle (100,200),rgb(0,255,0)的语句如何在VB中使用啊?
急用啊!!!!!!!!
解析:
VB与VB不同。
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
参考一下下面这段代码:
‘ 首先picturebox1 加载一张图像
FolderBrowserDialog1.Description = "选择图片文件夹导入图片"
FolderBrowserDialog1.ShowDialog()
path = FolderBrowserDialog1.SelectedPath()
If path = "" Then Return
strSrcFile = Dir(path "\*.tif")
PictureBox1.Image = Image.FromFile(path "\" strSrcFile)
’ 然后再在picturebox1中用graphic画图而不清空原图像
' 建立一个画图对象
Dim g As Graphics = Me.PictureBox1.CreateGraphics
‘ 定义画笔
Dim myPen As System.Drawing.Pen = New System.Drawing.Pen(Color.Blue)
’ 画出矩形框并且填充颜色(颜色保持50%的透明度,使得下面原来的图片背景能看得到)
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))
' 最后释放画图对象
g.Dispose()
效果大致如下图所示:
。net 不用api就行
缩放操作
Function 缩放(ByVal bitmap As Bitmap, ByVal 倍数 As Single) As Bitmap
Dim w As Integer = bitmap.Width * 倍数
Dim h As Integer = bitmap.Height * 倍数
Dim tem As New Bitmap(w, h)
Dim g As Graphics = Graphics.FromImage(tem)
g.DrawImage(bitmap, New Rectangle(0, 0, w, h), New Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel)
g.Dispose()
Return tem
End Function
鼠标滚轮事件 MouseWheel
MouseEventArgs.Delta 值可以判断滚动方向