定义了一个textbox,在buttonclick事件下点击后向一个double变量传送但是提示system::string ^ 无法转换为double该如何解决?

解决方案 »

  1.   

    另问下拉空间combox的返回值是哪个函数?应该如何判断?
      

  2.   

    可以用atof来解决,实现字符串转换为浮点型数字。
      

  3.   

    同2楼的,因为是C++/CLI,所以使用Convert方法最简单。
    可以读取Combo的当前被选择项,用GetCurSel()函数。
      

  4.   

    CString strP;
            pComboBoxPN->GetLBText(pComboBoxPN->GetCurSel(),strP);
      

  5.   

    但是我添加了convert::double之后显示如下错误
    错误 1 error C2248: “System::Windows::Forms::Control::text”: 无法访问 private 成员(在“System::Windows::Forms::Control”类中声明) c:\documents and settings\administrator\桌面\calcwindows\calcwindows\Form1.h 1075
    何解?
      

  6.   

    double a=System::Convert::ToDouble(textBox1->Text);
      

  7.   

    你怎么用的?.....ToDouble(textBox1->Text);  ?
      

  8.   

    就是这样用的,textbo1也设为pubilc了,但是仍旧提示无法访问。。
      

  9.   

    在一个button_click事件的响应中创建的在调用combo的时间的时候建立的cstring是使用/md命令行进行编译,但是我是用/clr的,报错,怎么办
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) //点击计算时的事件
     {
     if(this->SingleLineButton->Checked==true)
     {
     double a = Convert::ToDouble(Line1AAmp->text); Cstring i;
    i=this->CableTypeCombo->GetItemText(i);

    this->Line1AOut->Text = Convert::ToString(i);//这里想检测一下输入是否正确
     //CalcSingle::InputPet(
     }
     else
     {  }  }
      

  10.   

     Cstring i;
     i=this->CableTypeCombo->GetItemText(i);
     this->Line1AOut->Text = Convert::ToString(i);//这里想检测一下输入是否正确
    上面这几行,改成下面这样试试看:
    //这个是获得当前被选中的项的内容,就是那个字符串
    this->Line1AOut->Text=CableTypeCombo->SelectedText;
    //这个是获得当前被选中的是第几项
    this->Line1AOut->Text=CableTypeCombo->SelectedIndex.ToString();
      

  11.   


    13楼的代码就是在什么地方调用的转换程序但是无法使用,有办法吗出错信息如下错误 1 error C2248: “System::Windows::Forms::Control::text”: 无法访问 private 成员(在“System::Windows::Forms::Control”类中声明) c:\documents and settings\administrator\桌面\calcwindows\calcwindows\Form1.h 1100
      

  12.   

    出错的不是combo的属性,而是                 double a = Convert::ToDouble(Line1AAmp->text);
      

  13.   

    可以给出更多的代码看一下吗,包含那个textbox的声明之类的。
      

  14.   

    基本就是这样,其他的跟这个函数有关的基本没有了其他的数据看CLR的windows窗体就可以明白了
    public: System::Windows::Forms::TextBox^  Line1AAmp;
    // 
    // SingleLinePanel
    // 
    this->SingleLinePanel->Controls->Add(this->Line1CAng);
    this->SingleLinePanel->Controls->Add(this->label15);
    this->SingleLinePanel->Controls->Add(this->label16);
    this->SingleLinePanel->Controls->Add(this->Line1CAmp);
    this->SingleLinePanel->Controls->Add(this->Line1BAng);
    this->SingleLinePanel->Controls->Add(this->label13);
    this->SingleLinePanel->Controls->Add(this->label14);
    this->SingleLinePanel->Controls->Add(this->Line1BAmp);
    this->SingleLinePanel->Controls->Add(this->Line1AAng);
    this->SingleLinePanel->Controls->Add(this->label12);
    this->SingleLinePanel->Controls->Add(this->label11);
    this->SingleLinePanel->Controls->Add(this->Line1AAmp);
    this->SingleLinePanel->Location = System::Drawing::Point(5, 41);
    this->SingleLinePanel->Name = L"SingleLinePanel";
    this->SingleLinePanel->Size = System::Drawing::Size(278, 111);
    this->SingleLinePanel->TabIndex = 32; // 
    // Line1AAmp
    // 
    this->Line1AAmp->Location = System::Drawing::Point(103, 7);
    this->Line1AAmp->Name = L"Line1AAmp";
    this->Line1AAmp->Size = System::Drawing::Size(76, 21);
    this->Line1AAmp->TabIndex = 16;
    this->Line1AAmp->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
      

  15.   

    你的大小写弄错了:
    double a = Convert::ToDouble(Line1AAmp->text);
    这里的text应该改成Text,所以应该像下面这样:
    double a = Convert::ToDouble(Line1AAmp->Text);