OpenFileDialog.ShowReadOnly-Eigenschaft
Ruft einen Wert ab, der angibt, ob das Dialogfeld ein schreibgeschütztes Kontrollkästchen enthält, oder legt diesen fest.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Property ShowReadOnly As Boolean
'Usage
Dim instance As OpenFileDialog
Dim value As Boolean
value = instance.ShowReadOnly
instance.ShowReadOnly = value
public bool ShowReadOnly { get; set; }
public:
property bool ShowReadOnly {
bool get ();
void set (bool value);
}
/** @property */
public boolean get_ShowReadOnly ()
/** @property */
public void set_ShowReadOnly (boolean value)
public function get ShowReadOnly () : boolean
public function set ShowReadOnly (value : boolean)
Eigenschaftenwert
true, wenn das Dialogfeld ein Kontrollkästchen für den Schreibschutz enthält, andernfalls false. Der Standardwert ist false.
Beispiel
Im folgenden Codebeispiel wird die Verwendung der ShowReadOnly-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, wird die OpenFile-Methode 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
OpenFileDialog.ReadOnlyChecked-Eigenschaft