私のプログラムでは、ユーザーに保存フォルダーを選択させる必要があります。これを行うには、SelectedPathをMyComputerに設定します。
私の問題は、[OK]ボタンが最初は無効になっていないことです。
行動:
- 「マイコンピュータ」が選択されていますが(灰色の薄い色合い)、[OK]ボタンが有効になっています。
- [マイコンピュータ]をクリックすると(選択範囲が濃い青で表示されます)、[OK]ボタンが選択されたままになります。
- 「デスクトップ」を選択してから「マイコンピュータ」を再度選択すると、[OK]ボタンが無効になります。
SelectedPathとRootFolderの両方を、Environment.SpecialFolder.MyComputerとEnvironment.GetPath()とともに試してみましたが、役に立ちませんでした。
SelectedPathが有効なフォルダでない場合、どうすれば[OK]ボタンを無効にできますか?
編集: これは、Visual Studio 2010Professionalで開発されたWindowsXP、.Net4.0で実行されています。
編集#2:完全なサンプルコードが追加されました。
using System;
using System.Windows.Forms;
using System;
using System.Windows.Forms;
namespace FolderBrowser
{
public class Form1 : Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button button1;
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(10, 10);
this.button1.Text = "Open FolderBrowserDialog";
this.button1.Click += new System.EventHandler(this.SelectSaveFolderItem_Click);
this.Controls.Add(this.button1);
this.ResumeLayout(false);
}
public Form1()
{
InitializeComponent();
}
private void SelectSaveFolderItem_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
fbd.ShowDialog();
}
}