VB.NET只添加一张图片 [英] VB.NET Add only one picture

查看:199
本文介绍了VB.NET只添加一张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有图片浏览器,但打开整个文件夹,我想制作一些只打开一个名称为"W"的specyfic文件的东西。我不知道我能改变什么它会起作用。

I have picture brower but open whole folder and I want to make something that open only one specyfic file wiht have name "W". I do not have idea what can I change that it will be work.

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim cboItems As New List(Of String)
        ' Dim sb As New StringBuilder
        Dim z As String
        Dim w As String
        Dim currentCountry = CType(SamochodyBindingSource.Current, DataRowView).Row.Field(Of String)("Model")
        z = cbxMarka.Text
        SamochodyDataSet0.Samochody.Where(Function(row) row.Marka = z).Select(Function(row) row.Identyfikator).ToList().ForEach(Sub(Identyfikator) cboItems.Add(Identyfikator))
        ComboBox2.DataSource = cboItems
        w = ComboBox2.Text
        MsgBox(w)


        Dim dlgOtworz As New FolderBrowserDialog
        dlgOtworz.ShowNewFolderButton = False
        lbxPliki.Items.Clear()
        Me.Text = "Przeglądarka"
        If dlgOtworz.ShowDialog = DialogResult.OK Then
            Folder = dlgOtworz.SelectedPath
            Dim plik As FileInfo
            Dim katalog As New DirectoryInfo(dlgOtworz.SelectedPath)
            listaP = katalog.GetFiles("*.jpg")
            If listaP.Length < 1 Then
                MessageBox.Show("W wybranym folderze brak JPG", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                For Each plik In listaP
                    lbxPliki.Items.Add(plik.Name)
                Next
            End If
        End If
    End Sub

推荐答案

嗨Gajus21,

Hi Gajus21,

> ;> ...只打开一个名称为"W"的特定文件

>> … open only one specyfic file wiht have name "W"

你能解释一下这意味着什么吗?名为"W"的文件或文件名称是否包含"W"?

Could you explain what it means? Whether the file named "W", or the file's name contains "W"?

如果要查找名为"W"的文件,可以在使用时设置过滤器"&的GetFiles ;. QUOT修改后的代码如下所示。

If you want to find the file named "W", you can set the filter when using "GetFiles". The modified code is shown as follows.

    Dim result As DialogResult = dialog.ShowDialog()

    If result = DialogResult.OK Then
        Dim di As DirectoryInfo = New DirectoryInfo(dialog.SelectedPath)
        ‘ modify the following line
        Dim listaP As FileInfo() = di.GetFiles("W.jpg")

        If listaP.Length < 1 Then
            MessageBox.Show("W wybranym folderze brak JPG", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else

            For Each plik In listaP
                listBox1.Items.Add(plik.Name)
            Next
        End If
    End If

问候,

Kyle


这篇关于VB.NET只添加一张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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