Begginer code

I'm trying to write a really easy program, one that will open a new window, with 3 text boxes, 2 buttons and a web browser. First two fields will be for userID and password, and the third, which must initially be unselectable, should be the URL provider for the web browser. The two buttons: Logout and Login. The third text box becomes available only after logging in. Here is the code for the object functions:

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

if(textBox1->Text =="User1" && textBox2->Text =="zxc")

{

textBox3->CanSelect =true;

}

else

{

textBox3->CanSelect =false;

}

}

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {

textBox3->CanSelect =false;

webBrowser1->Url =" ";

}

private: System::Void textBox3_TextChanged(System::Object^ sender, System::EventArgs^ e) {

webBrowser1->Url = textBox3->Text;

}

I'm having problems with textBox3->CanSelect property. As far as I've seen, this is a bool that tells whether the box is or is not selectable by the user. Anyway, when I compile, it says:

error C2039: 'set' : is not a member of 'System::Windows::Forms::Control::CanSelect'

and

see declaration of 'System::Windows::Forms::Control::CanSelect' wherever I try to use it. I can't understand what it wants to say. And, if i can't set the value of CanSelect, then how am I supposed to make a text box from selectable to unselectable?

Sorry for the long post.

[2031 byte] By [maest] at [2007-12-24]
# 1
The property CanSelect is read-only - i.e. it tells you whether or not the control is 'selectable'. In order to modify this you need to set the ControlStyle this is done with SetStyle.
JonathanCaves-MSFT at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 2
Oh, Thank you very much. :)
maest at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 3
Sorry to bother you again, but I've encountered another problem. I tried to use the SetStyle method to make the textBox selectable and non-selectable. The code:

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

if(textBox1->Text == "Maest" && textBox2->Text == "zxc")

{

textBox3->SetStyle(ControlStyles::Selectable, true);

textBox3->UpdateStyles();

}

else

{

textBox3->SetStyle(ControlStyles::Selectable, false);

textBox3->UpdateStyles();

}

}

All of this is from the public ref class Form1, which was automaticaly defined when I made the window using the editor. Anyway, when compiling it said that friend function isn't accesible. From what I can tell from the "How do I" section, the SetStyle function and the UpdateStyles() function have to be declared inside the class. I've tried that, declaring them both private and public, but it didn't work, the compiler gave thwe same errors. Can someone tell me what I did wrong?

Again, sorry for the long post.

maest at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 4
The functions SetStyle and UpdateStyle are members of the Control class so you don't need to declare them yourself. What exactly is the error message you are getting?
JonathanCaves-MSFT at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 5

error C3767: 'System::Windows::Forms::Control::UpdateStyles': candidate function(s) not accessible

and

error C3767: 'System::Windows::Forms::Control::SetStyle': candidate function(s) not accessible

Well, if they are part of the Control class, shouldn't the class be mentioned somewhere in the code, or can it be used regardless of the class being used?

Thanks for the help. :)

maest at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 6

The Control class is the base-class of all controls - it is also a base-class of the Form class.

The UpdateStyle and SetStyle methods are protected methods - this means that you can only access them from the scope of a class that inherits from the Control class. So you need to set it on your Form instead of on the individual controls.

JonathanCaves-MSFT at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 7
I'm sorry, but could you please elaborate? I'm a begginer in OOP, and I'm having a difficult time understanding how classes work. The Form1 class (the class in which that code is) is derived from the base class System::Windows::Forms::Form. SetStyle and UpdateStyle are protected methods within System::Windows::Forms::Control class. Because they are protected, does that mean that I cannot use them outside the scope of their class or of a class derived from their class? Then how am I supposed to change the style of the objects found in Form1 class? Should I define another class derived from System::Windows::Forms::Control, and change the styles of the objects there? Is that even possible?
maest at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 8
As Control is a base-class of System::Windows::Forms::Form its protected methods should be accessible from within your form. Try something like this->SetStyle(...); this->UpdateStyle(); with a member function of your form.
JonathanCaves-MSFT at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...