vb.net选中图形 vbs编写图形窗口

vb.net中,如何点击按钮调出选择文件窗口选中图片并在picturebox中显示出来?button , OpenFileDialog , PictureBox , textbox 控件,我把图片显示在 picturebox 中,而路
径存放在 textbox 中,不知道这样行不行 。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filename As String
OpenFileDialog1.Filter = "jpg files (*.jpg)|*.jpg"
OpenFileDialog1.FilterIndex = 1
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
filename = OpenFileDialog1.FileName
Else
End
End If
If Not (PictureBox1.Image Is Nothing) Then
PictureBox1.Image.Dispose()
PictureBox1.Image = Nothing
End If
'PictureBox1.Image = System.Drawing.Image.FromFile(filename)
去掉注释后就显示图片
TextBox1.Text = filename
End Sub
picturebox中只记录文件存放的路径,我找了一个 ImageLocation 函数
PictureBox1.ImageLocation = filename 不过还是会显示图片
Vb.net怎么实现图像的处理这问题有点笼统 , 软糖来说说把:
图像处理由System.Drawing命名空间负责 。
主要是Bitmap类和Graphics类 。
Bitmap表示一个位图,可以是BMP,JPG,PNG等文件 。
装载位图
Dim 位图 As Bitmap = Bitmap.FromFile("C:\Image1.PNG")
Graphics表示一张画纸,能够进行绘制操作 。
它可以被窗体、控件、位图调用CreateGraphics()方法来创建 。
然后调用Graphics.Draw开头的一系列函数来绘制图像和图形 , Fill开头的填充图形 。
创建画纸并绘制位图
Dim 画纸 As Graphics = Me.CreateGraphics()
画纸.DrawImage(位图, 100, 100, 256, 256)
可以将上面三行放到Form1_Load中测试,把路径改一下,
还可以把Me改为能在上面绘图的控件的名称 。
更多内容请看MSDN的System.Drawing命名空间 。
如满意,请采纳 , 谢谢 。
VB.NET我要用鼠标轨迹画一个矩形框 然后选中控件 。就像星际和魔兽争霸里对部队单位的选中一样~等大神回答这个类继承自Panel , 把它加到你的项目里面,先运行一下,然后从工具箱里把它拖到窗体上,然后再向里面添加其它控件就可以了,支持Shift加选,Alt减选
Imports System.Linq
Imports System.Collections
Public Class MyPanel
Inherits Panel
' 选择模式,相交还是包含
Enum SelectMode
Intersects
Contains
End Enum
Dim down As New Point(-1, -1)
Dim rect As Rectangle
Dim selected As New List(Of Control)
Dim editting As IEnumerable(Of Control)
Dim mode As SelectMode = SelectMode.Contains
Dim shift, alt As Boolean
Public Sub New()
Me.DoubleBuffered = True
End Sub
Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
MyBase.OnMouseDown(e)
down = e.Location
editting = selected.ToArray().ToList()
OnMouseMove(e)
End Sub
Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
MyBase.OnMouseMove(e)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim loc As New Point(Math.Min(down.X, e.X), Math.Min(down.Y, e.Y))
【vb.net选中图形 vbs编写图形窗口】Dim size As New Size(Math.Abs(down.X - e.X), Math.Abs(down.Y - e.Y))
rect = New Rectangle(loc, size)
Dim cs As New List(Of Control)
For Each c In Controls
cs.Add(c)
Next
Dim a = cs.Where(Function(n As Control) (mode = SelectMode.Contains And rect.Contains(n.Bounds)) Or (mode = SelectMode.Intersects And rect.IntersectsWith(n.Bounds)))
If shift Then editting = a.Union(selected) Else If alt Then editting = selected.Except(a) Else editting = a
Invalidate()
End If
End Sub
Protected Overrides Sub OnMouseUp(e As MouseEventArgs)

推荐阅读