Faire des boites de dialogues complêtes

Contenu du snippet

OPENFILEDIALOG
Try
            With odlgTextFile
                .CheckFileExists = True
                .CheckPathExists = True
                .DefaultExt = "txt"
                .DereferenceLinks = True
                .Filter = "Text files (*.txt)|*.txt|All files|*.*"
                .Multiselect = False
                .RestoreDirectory = True
                .ShowHelp = True
                .ShowReadOnly = False
    .ReadOnlyChecked = False
                .Title = "Select a file to open"
                .ValidateNames = True
If .ShowDialog = Windows.Forms.DialogResult.OK Then
                    Try
                    Catch fileException As Exception
                        Throw fileException
                    End Try
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
        End Try



SAVEFILEDIALOG

Try
            With sdlgTextFile
                .AddExtension = True
                .CheckPathExists = True
                .CreatePrompt = False
                .OverwritePrompt = True
                .ValidateNames = True
                .ShowHelp = True
                .DefaultExt = "txt"
                .FileName = filename
                .Filter = _
                "Text files (*.txt)|*.txt|" & _
                "All files|*.*"
                .FilterIndex = 1
                If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
        End Try
COLORDIALOG
   Static CustomColors() As Integer = _
         {RGB(255, 0, 0), RGB(0, 255, 0), RGB(0, 0, 255)}
        Try
            With cdlgText
                .Color = txtFileContents.ForeColor
                .CustomColors = CustomColors
                .AllowFullOpen = True.
                .AnyColor = True
                .FullOpen = False
                .SolidColorOnly = True
                .ShowHelp = True
                If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                    txtFileContents.ForeColor = .Color
                    ' Store the custom colors for future use. 
                    CustomColors = .CustomColors
                End If
                cdlgText.Reset()
            End With
            'With cdlgText
            '  .Color = txtFileContents.ForeColor
            '  If .ShowDialog() = DialogResult.OK Then
            '    
            '  End If
            'End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
        End Try
FONTDIALOG
Try
            With fdlgText
                .Font = txtFileContents.Font
                .Color = txtFileContents.ForeColor
                .ShowColor = True
                .ShowApply = True
                .ShowEffects = True
                .ShowHelp = True
                .AllowScriptChange = True
                .AllowSimulations = False
                .AllowVectorFonts = False
                .AllowVerticalFonts = False
                .FixedPitchOnly = False
                .FontMustExist = True
                .MaxSize = 48
                .MinSize = 8
                If .ShowDialog = Windows.Forms.DialogResult.OK Then
                    txtFileContents.Font = .Font
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
        End Try
EPLORATEUR WINDOWS DE DOSSIERS (PETITE FENETRE CARREE)
Try
            With fldlgList
                .RootFolder = Environment.SpecialFolder.Personal
                .Description = "Select the directory you want to use as the default."
                .ShowNewFolderButton = True
                If .ShowDialog = Windows.Forms.DialogResult.OK Then
                    'txtDirectory.Text = .SelectedPath
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
        End Try
EXPLORATEUR WINDOWS DE FICHIERS ET DOSSIERS
Try
            With odlgFileNames
                .Reset()
                .InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Temp
                .AddExtension = True
                .CheckFileExists = True
                .CheckPathExists = True
                .DefaultExt = "txt"
                .DereferenceLinks = True
                .Filter = _
                "Text files (*.txt)|*.txt|" & _
                "All files|*.*"
                .Multiselect = True
                .RestoreDirectory = True
                .ShowHelp = True
                .ShowReadOnly = False
                .Title = "Select a file"
                .ValidateNames = True
                If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                    lstFiles.DataSource = .FileNames
                    'Dim strName As String
                    'For Each strName In .FileNames
                    '    lstFiles.Items.Add(strName)
                    'Next
                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
        End Try


Compatibilité : VB 2005, VB.NET 1.x

Disponible dans d'autres langages :

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.