Freigeben über


OpenFileDialog.ReadOnlyChecked-Eigenschaft

Ruft einen Wert ab, der angibt, ob das Kontrollkästchen für den Schreibschutz aktiviert ist, oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property ReadOnlyChecked As Boolean
'Usage
Dim instance As OpenFileDialog
Dim value As Boolean

value = instance.ReadOnlyChecked

instance.ReadOnlyChecked = value
public bool ReadOnlyChecked { get; set; }
public:
property bool ReadOnlyChecked {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_ReadOnlyChecked ()

/** @property */
public void set_ReadOnlyChecked (boolean value)
public function get ReadOnlyChecked () : boolean

public function set ReadOnlyChecked (value : boolean)

Eigenschaftenwert

true, wenn das Kontrollkästchen für den Schreibschutz aktiviert ist, andernfalls false. Der Standardwert ist false.

Hinweise

Der ReadOnlyChecked-Zustand hat keine Auswirkungen auf den Lese-/Schreibmodus, mit dem OpenFileDialog.OpenFile eine im Dialogfeld ausgewählte Datei öffnet. OpenFile öffnet eine Datei immer im schreibgeschützten Modus.

Die ShowReadOnly-Eigenschaft muss festgelegt werden, bevor das Kontrollkästchen für den Schreibschutz im Dialogfeld angezeigt werden kann.

Beispiel

Im folgenden Codebeispiel wird die Verwendung der ReadOnlyChecked-Eigenschaft veranschaulicht. In diesem Beispiel wird das OpenFileDialog-Dialogfeld angezeigt, wobei die ShowReadOnly-Eigenschaft auf true festgelegt ist. Wenn der Benutzer auf die Option klickt, mit der die Datei im schreibgeschützten Modus geöffnet wird, hat die ReadOnlyChecked-Eigenschaft den Wert true, und dieOpenFile-Methode wird verwendet, um die Datei zu öffnen. Andernfalls wird die FileStream-Klasse verwendet, um die Datei im schreibgeschützten Modus zu öffnen.

Private Function OpenFile() As FileStream

    ' Displays an OpenFileDialog and shows the read/only files.

    Dim DlgOpenFile As New OpenFileDialog()
    DlgOpenFile.ShowReadOnly = True
    Dim Fs As FileStream

    If DlgOpenFile.ShowDialog() = DialogResult.OK Then

        ' If ReadOnlyChecked is true, uses the OpenFile method to
        ' open the file with read/only access.

        If DlgOpenFile.ReadOnlyChecked = True Then

            Return DlgOpenFile.OpenFile()

            ' Otherwise, opens the file with read/write access.

        Else

            Dim Path As String = DlgOpenFile.FileName
            Return New FileStream(Path, System.IO.FileMode.Open, _
                    System.IO.FileAccess.ReadWrite)


        End If

    End If


End Function
private FileStream OpenFile()
{
    // Displays an OpenFileDialog and shows the read/only files.

    OpenFileDialog dlgOpenFile = new OpenFileDialog();
    dlgOpenFile.ShowReadOnly = true;


    if(dlgOpenFile.ShowDialog() == DialogResult.OK)
    {

        // If ReadOnlyChecked is true, uses the OpenFile method to
        // open the file with read/only access.

        if(dlgOpenFile.ReadOnlyChecked == true)
        {
            return (FileStream)dlgOpenFile.OpenFile();

        }

        // Otherwise, opens the file with read/write access.

        else
        {
            string path = dlgOpenFile.FileName;
            return new FileStream(path, System.IO.FileMode.Open, 
                    System.IO.FileAccess.ReadWrite);
        }


    }

    return null;


}
private:
   FileStream^ OpenFile()
   {
      // Displays an OpenFileDialog and shows the read/only files.
      OpenFileDialog^ dlgOpenFile = gcnew OpenFileDialog;
      dlgOpenFile->ShowReadOnly = true;
      if ( dlgOpenFile->ShowDialog() == ::DialogResult::OK )
      {
         // If ReadOnlyChecked is true, uses the OpenFile method to
         // open the file with read/only access.
         if ( dlgOpenFile->ReadOnlyChecked == true )
         {
            return dynamic_cast<FileStream^>(dlgOpenFile->OpenFile());
         }
         // Otherwise, opens the file with read/write access.
         else
         {
            String^ path = dlgOpenFile->FileName;
            return gcnew FileStream( path,System::IO::FileMode::Open,System::IO::FileAccess::ReadWrite );
         }
      }

      return nullptr;
   }
private FileStream OpenFile()
{
    // Displays an OpenFileDialog and shows the read/only files.
    OpenFileDialog dlgOpenFile = new OpenFileDialog();
    dlgOpenFile.set_ShowReadOnly(true);
    if (dlgOpenFile.ShowDialog().Equals(get_DialogResult().OK)) {
        // If ReadOnlyChecked is true, uses the OpenFile method to
        // open the file with read/only access.
        if (dlgOpenFile.get_ReadOnlyChecked() == true) {
            return (FileStream)dlgOpenFile.OpenFile();
        }
        // Otherwise, opens the file with read/write access.
        else {
            String path = dlgOpenFile.get_FileName();
            return new FileStream(path, System.IO.FileMode.Open,
                System.IO.FileAccess.ReadWrite);
        }
    }
    return null;
} //OpenFile 

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

OpenFileDialog-Klasse
OpenFileDialog-Member
System.Windows.Forms-Namespace
ShowReadOnly