VB.NET浏览用户控件属性中的文件 [英] VB.NET Browse File in User Control Property

查看:93
本文介绍了VB.NET浏览用户控件属性中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在创建我的第一个用户控件,一个图像查看器。我有一个属性 Image (String),这个工作正常,但不是用户友好的。您需要键入整个路径或复制并粘贴路径。有人可以建议我浏览所有图像文件作为属性的代码。

Hello everyone,

I'm creating my first User Control, an Image Viewer. I have a property Image (String), this works fine but not user friendly. You need to key the whole path or copy and paste the path. Can someone suggest me a code that browse all images file as a property.

Property Image() As String
    Get
        Return ImgViewer.ImagePath
    End Get
    Set(ByVal value As String)
        ImgViewer.ImagePath = value
        If IO.File.Exists(ImgViewer.ImagePath) Then
            ImgViewer.Bmp = New Bitmap(ImgViewer.ImagePath)
            ImgViewer.TotalPage = ImgViewer.Bmp.GetFrameCount(Imaging.FrameDimension.Page)
            ImgViewer.CurrentPage = 1
            ImgViewer.Bmp.SelectActiveFrame(Imaging.FrameDimension.Page, ImgViewer.CurrentPage - 1)
            PictureBox1.Image = ImgViewer.Bmp
            ImgViewer.Width = ImgViewer.Bmp.Width
            ImgViewer.Height = ImgViewer.Bmp.Height
            PictureBox1.Width = ImgViewer.Width
            PictureBox1.Height = ImgViewer.Height
            ImgViewer.Rotate = Rotation.Rotate0
            ImgViewer.Fit = ZoomFit.None
            ImgViewer.Zoom = 0
            ImgViewer.Percent = 1.0
            ImgViewer.Invert = False
            PercentW = (ImgViewer.Width * 0.01)
            PercentH = (ImgViewer.Height * 0.01)
        End If
    End Set
End Property

推荐答案

参见 OpenFileDialog [ ^ ]示例。



您应指定Filter属性以允许选择图像文件只有。



在你的c ase你可以使用FileNames属性来获取所选的文件名。
See OpenFileDialog[^] example on MSDN.

You should specify the Filter property to allow select image files only.

In your case you may use the FileNames property to get the selected file names.


解决它

添加代码到属性和参考 System.Design

Solve it
Added code to Property and Reference System.Design
Imports System.ComponentModel

<EditorAttribute(GetType(System.Windows.Forms.Design.FileNameEditor), GetType(System.Drawing.Design.UITypeEditor)), Browsable(True), Category("Image Details"), RefreshProperties(RefreshProperties.All)> _
Property Image() As String
    Get
        Return Path
    End Get
    Set(ByVal value As String)
        Path = value 
    End Set
End Property


这篇关于VB.NET浏览用户控件属性中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆