我对 C++ 很陌生,我正在用 Visual C++ 编写程序。在出现此错误之前,一切都很顺利:
error C2440: '==' : cannot convert from 'const char [11]' to'System::Windows::Forms::TextBox ^'
我很确定这与我在文本框中输入数字而不是单词有关。
这是代码的一部分:
if (fnum==true){
if (phoneNum=="555555555"){ // i think this part causes the problem
//code for when the phone number is correct
} else {
//if phone number is not correct
}
}
我尝试使用“5555555555”而不是“5555555555”,但它给了我一个不同的错误
error C2015: too many characters in constant
error C2446: '==' : no conversion from 'int' to 'System::Windows::Forms::TextBox ^'
继承人的其余代码:
#pragma once
#include <stdio.h>
#include <Windows.h>
bool fnum = true;
bool vis=true;
namespace Items {
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 Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
static int tim = 0;
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ Searcher;
private: System::Windows::Forms::Button^ search;
private: System::Windows::Forms::PictureBox^ usb_key;
private: System::Windows::Forms::PictureBox^ help;
private: System::Windows::Forms::PictureBox^ yahoo_passcode;
private: System::Windows::Forms::Timer^ timer1;
private: System::Windows::Forms::PictureBox^ yahoo_Passcode2;
private: System::Windows::Forms::TextBox^ phoneNum;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
#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->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->Searcher = (gcnew System::Windows::Forms::TextBox());
this->search = (gcnew System::Windows::Forms::Button());
this->usb_key = (gcnew System::Windows::Forms::PictureBox());
this->help = (gcnew System::Windows::Forms::PictureBox());
this->yahoo_passcode = (gcnew System::Windows::Forms::PictureBox());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->yahoo_Passcode2 = (gcnew System::Windows::Forms::PictureBox());
this->phoneNum = (gcnew System::Windows::Forms::TextBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->usb_key))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->help))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_passcode))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_Passcode2))->BeginInit();
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Quartz", 20, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->ForeColor = System::Drawing::SystemColors::ActiveCaption;
this->label1->Location = System::Drawing::Point(12, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(84, 30);
this->label1->TabIndex = 0;
this->label1->Text = L"Items";
//
// button1
//
this->button1->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->button1->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
this->button1->Font = (gcnew System::Drawing::Font(L"Quartz", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->button1->Location = System::Drawing::Point(661, 9);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(52, 21);
this->button1->TabIndex = 1;
this->button1->Text = L"Exit";
this->button1->UseVisualStyleBackColor = false;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Searcher
//
this->Searcher->BackColor = System::Drawing::SystemColors::InactiveCaption;
this->Searcher->BorderStyle = System::Windows::Forms::BorderStyle::None;
this->Searcher->Font = (gcnew System::Drawing::Font(L"Quartz", 14.25F, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)),
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
this->Searcher->Location = System::Drawing::Point(12, 82);
this->Searcher->Name = L"Searcher";
this->Searcher->Size = System::Drawing::Size(741, 22);
this->Searcher->TabIndex = 2;
this->Searcher->Click += gcnew System::EventHandler(this, &Form1::Searcher_Click);
this->Searcher->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
//
// search
//
this->search->Location = System::Drawing::Point(362, 28);
this->search->Name = L"search";
this->search->Size = System::Drawing::Size(1, 1);
this->search->TabIndex = 3;
this->search->Text = L"button2";
this->search->UseVisualStyleBackColor = true;
this->search->Click += gcnew System::EventHandler(this, &Form1::search_Click);
//
// usb_key
//
this->usb_key->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"usb_key.Image")));
this->usb_key->Location = System::Drawing::Point(-95, 142);
this->usb_key->Name = L"usb_key";
this->usb_key->Size = System::Drawing::Size(866, 464);
this->usb_key->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->usb_key->TabIndex = 4;
this->usb_key->TabStop = false;
this->usb_key->Visible = false;
//
// help
//
this->help->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"help.Image")));
this->help->Location = System::Drawing::Point(49, 259);
this->help->Name = L"help";
this->help->Size = System::Drawing::Size(664, 234);
this->help->TabIndex = 5;
this->help->TabStop = false;
this->help->Visible = false;
//
// yahoo_passcode
//
this->yahoo_passcode->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"yahoo_passcode.Image")));
this->yahoo_passcode->Location = System::Drawing::Point(49, 142);
this->yahoo_passcode->Name = L"yahoo_passcode";
this->yahoo_passcode->Size = System::Drawing::Size(663, 444);
this->yahoo_passcode->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->yahoo_passcode->TabIndex = 6;
this->yahoo_passcode->TabStop = false;
this->yahoo_passcode->Visible = false;
//
// timer1
//
this->timer1->Interval = 1000;
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// yahoo_Passcode2
//
this->yahoo_Passcode2->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"yahoo_Passcode2.Image")));
this->yahoo_Passcode2->Location = System::Drawing::Point(50, 142);
this->yahoo_Passcode2->Name = L"yahoo_Passcode2";
this->yahoo_Passcode2->Size = System::Drawing::Size(663, 444);
this->yahoo_Passcode2->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->yahoo_Passcode2->TabIndex = 7;
this->yahoo_Passcode2->TabStop = false;
this->yahoo_Passcode2->Visible = false;
//
// phoneNum
//
this->phoneNum->BackColor = System::Drawing::SystemColors::InactiveCaptionText;
this->phoneNum->BorderStyle = System::Windows::Forms::BorderStyle::None;
this->phoneNum->Font = (gcnew System::Drawing::Font(L"Garamond", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->phoneNum->ForeColor = System::Drawing::Color::Lime;
this->phoneNum->Location = System::Drawing::Point(128, 224);
this->phoneNum->Name = L"phoneNum";
this->phoneNum->Size = System::Drawing::Size(487, 21);
this->phoneNum->TabIndex = 8;
this->phoneNum->Enter += gcnew System::EventHandler(this, &Form1::textBox1_Enter);
this->phoneNum->Leave += gcnew System::EventHandler(this, &Form1::textBox1_Leave);
//
// Form1
//
this->AcceptButton = this->search;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::ActiveCaptionText;
this->ClientSize = System::Drawing::Size(765, 621);
this->Controls->Add(this->phoneNum);
this->Controls->Add(this->yahoo_Passcode2);
this->Controls->Add(this->yahoo_passcode);
this->Controls->Add(this->help);
this->Controls->Add(this->usb_key);
this->Controls->Add(this->search);
this->Controls->Add(this->Searcher);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
this->MaximizeBox = false;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->usb_key))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->help))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_passcode))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_Passcode2))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
if (Searcher->Text=="") { //when the text box has no text in it anymore
usb_key->Visible = false;
help->Visible = false;
yahoo_passcode->Visible = false;
yahoo_Passcode2->Visible = false;
timer1->Enabled = false;
}
}
private: System::Void search_Click(System::Object^ sender, System::EventArgs^ e) {
//when the search button is pressed.
/////////////////////////////////////////////////////
if (fnum==true){
if (phoneNum=='5555555555'){
//code for when the phone number is correct
} else {
//if phone number is not correct
}
}
///////////////////////////////////////////////////
if (Searcher->Text=="usb key") {
usb_key->Visible = vis;
}
else if (Searcher->Text=="USB key"){
usb_key->Visible = vis;
}
else if (Searcher->Text=="Usb key") {
usb_key->Visible = true;
}
else if (Searcher->Text=="help") {
help->Visible = true;
}
else if (Searcher->Text=="yahoo password") {
yahoo_passcode->Visible = true;
timer1->Enabled = true;
}
}
private: System::Void Searcher_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
tim++;
if (tim==4) {
timer1->Enabled = false;
yahoo_Passcode2->Visible = true;
yahoo_passcode->Visible = false;
}
}
private: System::Void textBox1_Enter(System::Object^ sender, System::EventArgs^ e) {
fnum = true;
}
private: System::Void textBox1_Leave(System::Object^ sender, System::EventArgs^ e) {
fnum = false;
}
};
}
正如我之前所说,我是 C++ 新手,我真的不太了解,所以如果你能以简单的形式给出答案,那就太好了。比如展示要改变什么以及它做了什么。
提前致谢。