如何清除“打开文件”对话框历史记录

时间:2014-02-17 14:03:06

标签: vb.net

我在下面有这个代码。这是发生了什么以及我做了什么:

  1. 点击按钮,然后选择一张照片。
  2. 再次单击该按钮,然后选择10个以上的图像。将弹出一个消息框,说“只需要10张照片”。 我的问题是,消息框显示两次。
  3. 当我再次单击该按钮并再次选择10个以上的图像时,消息框将显示三次。
  4. 有没有办法如何* 清除 openfiledialog,以便消息框只显示一次。

    顺便说一下,这是我的代码:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BtnBrowse.Click
            'Limits the number of photos to 10
            AddHandler OpenFileDialog1.FileOk, Sub(s, ce)
                                                   If OpenFileDialog1.FileNames.Length > 10 Then
                                                       MsgBox("Only 10 photos are needed.")
                                                       ce.Cancel = True
                                                   End If
                                               End Sub
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim images As String
    
                For Each images In OpenFileDialog1.FileNames
                    Dim pics As New PictureBox
    
                    'Sets the properties of the picturebox in the TableLayoutPanel
                    pics.Height = 120
                    pics.Width = 120
                    pics.SizeMode = PictureBoxSizeMode.StretchImage
                    pics.Image = Image.FromFile(images)
                    pics.Load(images)
    
                    'Add every images uploaded using the OpenFileDialog
                    TableLayoutPanelNitrogen.Controls.Add(pics)
    
                    'Sets the course of action based on the number of controls within the TableLayoutPanel
                    If TableLayoutPanelNitrogen.Controls.Count < 10 Then
                        Continue For
                    ElseIf TableLayoutPanelNitrogen.Controls.Count = 10 Then
                        BtnBrowse.Enabled = False
                        Exit For
                    ElseIf TableLayoutPanelNitrogen.Controls.Count > 10 Then
                        Exit For
                    End If
                Next images
            End If
        End Sub
    

0 个答案:

没有答案