C245条件表达式类型&System; Windows :: Forms :: DialogResult'是非法的

时间:2016-04-19 12:12:18

标签: c++ windows-forms-designer

我尝试打开文件夹并将结果放入文本框中。 但每当我检查用户是否选择了文件夹并按下确定时,它就会给我错误

C245 conditional expression of type 'System::Windows::Forms::DialogResult' is illegal

这是错误

的部分
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    System::Windows::Forms::DialogResult result = folderBrowserDialog1->ShowDialog();

    if (result = System::Windows::Forms::DialogResult::OK)
    {
        textBox1->Text = folderBrowserDialog1->SelectedPath;
    }
}
};

我也尝试过只使用DialogResult :: OK,但是这会导致错误消息说OK尚未声明,并且搜索google我发现System :: Windows :: Forms :: DialogResult :: OK应该然后使用。

这是我整个文件的源代码,因为我在那里做错了

#pragma once
#using <System.DLL>
#using <System.Drawing.DLL>
#using <System.Windows.Forms.DLL>

namespace MyProject {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for ConfigureScreen
/// </summary>
public ref class ConfigureScreen : public System::Windows::Forms::Form
{
public:
    ConfigureScreen(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~ConfigureScreen()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::FolderBrowserDialog^  folderBrowserDialog1;
private: System::Windows::Forms::TextBox^  textBox1;
private: System::Windows::Forms::Button^  button1;
protected:

protected:


private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog());
        this->textBox1 = (gcnew System::Windows::Forms::TextBox());
        this->button1 = (gcnew System::Windows::Forms::Button());
        this->SuspendLayout();
        //Forbid the user to create new folders when using folder browser.
        this->folderBrowserDialog1->ShowNewFolderButton = false;
        // 
        // textBox1
        // 
        this->textBox1->Location = System::Drawing::Point(32, 96);
        this->textBox1->Name = L"textBox1";
        this->textBox1->Size = System::Drawing::Size(234, 20);
        this->textBox1->TabIndex = 0;
        // 
        // button1
        // 
        this->button1->Location = System::Drawing::Point(272, 94);
        this->button1->Name = L"button1";
        this->button1->Size = System::Drawing::Size(75, 23);
        this->button1->TabIndex = 1;
        this->button1->Text = L"Browse";
        this->button1->UseVisualStyleBackColor = true;
        this->button1->Click += gcnew System::EventHandler(this, &ConfigureScreen::button1_Click);
        // 
        // ConfigureScreen
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(422, 345);
        this->Controls->Add(this->button1);
        this->Controls->Add(this->textBox1);
        this->Name = L"ConfigureScreen";
        this->Text = L"ConfigureScreen";
        this->ResumeLayout(false);
        this->PerformLayout();

    }
#pragma endregion

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    System::Windows::Forms::DialogResult result = folderBrowserDialog1->ShowDialog();

    if (result = System::Windows::Forms::DialogResult::OK)
    {
        textBox1->Text = folderBrowserDialog1->SelectedPath;
    }
}
};
}

1 个答案:

答案 0 :(得分:0)

==用于比较,但您使用的是=,这是一项值分配。

这应该有效:

if (result == System::Windows::Forms::DialogResult::OK)
{
    textBox1->Text = folderBrowserDialog1->SelectedPath;
}