phr0663r
December 19th, 2006, 08:07 AM
ok, first forum post and a newbee .net programmer so forgive a little please!
the problem is that when comparing the text property of two label's proves to always fail when
made from Args->KeyChar.ToString()
i made a little test program to isolate the issue which is here:
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Text;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public __gc class CGui : public Form {
public:
CGui(){
// initialise first label
this->myLabel01 = new Label();
this->myLabel01->Location = Drawing::Point(0,0);
this->myLabel01->Size = Drawing::Size(20,20);
this->myLabel01->Text = S"x";
this->Controls->Add(this->myLabel01);
// initialise second label
this->myLabel02 = new Label();
this->myLabel02->Location = Drawing::Point(50,0);
this->myLabel02->Size = Drawing::Size(20,20);
this->myLabel02->Text = S"x";
this->Controls->Add(this->myLabel02);
// add keypress event handler to set label text to key pressed
this->add_KeyPress(new KeyPressEventHandler(this,KeyPress));
// test that label's text match at begining of test
testString();
testString02();
// set label02's text value to not match label01's and re-test
this->myLabel02->Text = S"w";
testString();
testString02();
}
private:
Label * myLabel01;
Label * myLabel02;
void KeyPress(Object * Sender, KeyPressEventArgs * Args){
// set label's text value to the pressed key's char in string format
// this is where the error must occur
this->myLabel01->Text = Args->KeyChar.ToString();
this->myLabel02->Text = Args->KeyChar.ToString();
// run test again to evaluate change in label's text value
testString();
testString02();
}
void testString(){
if(this->myLabel01->Text == this->myLabel02->Text)
MessageBox::Show(S"both label's text values are the same value",S"String test 01");
else
MessageBox::Show(S"the label's text values are NOT the same value",S"String test 01");
}
void testString02(){
if(this->myLabel01->Text == this->myLabel01->Text)
MessageBox::Show(S"label01's text value is itself",S"String test 02");
else
MessageBox::Show(S"label01's text value is NOT itself!",S"String test 02");
}
};
int __stdcall WinMain(){
Application::Run(new CGui());
return 0;
}
can anyone tell me why once the keyPress func has been run the text values never match even when comparing label01->text with itself!
and any ideas to work around it?
the problem is that when comparing the text property of two label's proves to always fail when
made from Args->KeyChar.ToString()
i made a little test program to isolate the issue which is here:
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Text;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public __gc class CGui : public Form {
public:
CGui(){
// initialise first label
this->myLabel01 = new Label();
this->myLabel01->Location = Drawing::Point(0,0);
this->myLabel01->Size = Drawing::Size(20,20);
this->myLabel01->Text = S"x";
this->Controls->Add(this->myLabel01);
// initialise second label
this->myLabel02 = new Label();
this->myLabel02->Location = Drawing::Point(50,0);
this->myLabel02->Size = Drawing::Size(20,20);
this->myLabel02->Text = S"x";
this->Controls->Add(this->myLabel02);
// add keypress event handler to set label text to key pressed
this->add_KeyPress(new KeyPressEventHandler(this,KeyPress));
// test that label's text match at begining of test
testString();
testString02();
// set label02's text value to not match label01's and re-test
this->myLabel02->Text = S"w";
testString();
testString02();
}
private:
Label * myLabel01;
Label * myLabel02;
void KeyPress(Object * Sender, KeyPressEventArgs * Args){
// set label's text value to the pressed key's char in string format
// this is where the error must occur
this->myLabel01->Text = Args->KeyChar.ToString();
this->myLabel02->Text = Args->KeyChar.ToString();
// run test again to evaluate change in label's text value
testString();
testString02();
}
void testString(){
if(this->myLabel01->Text == this->myLabel02->Text)
MessageBox::Show(S"both label's text values are the same value",S"String test 01");
else
MessageBox::Show(S"the label's text values are NOT the same value",S"String test 01");
}
void testString02(){
if(this->myLabel01->Text == this->myLabel01->Text)
MessageBox::Show(S"label01's text value is itself",S"String test 02");
else
MessageBox::Show(S"label01's text value is NOT itself!",S"String test 02");
}
};
int __stdcall WinMain(){
Application::Run(new CGui());
return 0;
}
can anyone tell me why once the keyPress func has been run the text values never match even when comparing label01->text with itself!
and any ideas to work around it?