読み取り専用チェック ボックスがオンかオフかを示す値を取得または設定します。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
'宣言
Public Property ReadOnlyChecked As Boolean
'使用
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)
プロパティ値
読み取り専用チェック ボックスがオンの場合は true。それ以外の場合は false。既定値は false です。
解説
ReadOnlyChecked 状態は、ダイアログ ボックスで選択されているファイルを OpenFileDialog.OpenFile が開くときに使用する読み取り/書き込みモードには影響しません。OpenFile は、常に読み取り専用モードでファイルを開きます。
ダイアログ ボックスに読み取り専用チェック ボックスを表示するには、事前に ShowReadOnly プロパティを設定する必要があります。
使用例
ReadOnlyChecked プロパティの使用方法を示すコード例を次に示します。この例では、ShowReadOnly プロパティが true に設定された OpenFileDialog ボックスを表示します。オプションをクリックしてファイルを読み取り専用モードで開くと、ReadOnlyChecked プロパティは true と評価され、OpenFile メソッドを使用してファイルが開かれます。それ以外の場合は、FileStream クラスを使用して読み取り/書き込みモードでファイルが開かれます。
Private Function OpenFile() As FileStream
' Displays an OpenFileDialog and shows the read/only files.
Dim DlgOpenFile As New OpenFileDialog()
DlgOpenFile.ShowReadOnly = True
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
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
参照
関連項目
OpenFileDialog クラス
OpenFileDialog メンバ
System.Windows.Forms 名前空間
ShowReadOnly