Forms and labels

  • Thread starter Thread starter Allen Maki
  • Start date Start date
A

Allen Maki

Hi Everybody,



I am new to Famework Programming and I need your help.



In Visual C++ .NET

Forms.

Labels.



If I want to add XXXX to the label, I can do that through the "Text"
property in the property editor. But I want to add the XXXX during run
time. In other words I want the label to be written during run time.



void InitializeComponent(void)

{

//

// label2

//

this->label2->Location = System::Drawing::Point(32,16);

this->label2->Name = S"label2";

this->label2->Size = System::Drawing::Size(208, 23);

this->label2->TabIndex = 6;

this->label2->Text = S"XXXX";

}
 
Allen Maki said:
Hi Everybody,



I am new to Famework Programming and I need your help.



In Visual C++ .NET

Forms.

Labels.



If I want to add XXXX to the label, I can do that through the "Text"
property in the property editor. But I want to add the XXXX during run
time. In other words I want the label to be written during run time.



void InitializeComponent(void)

{

//

// label2

//

this->label2->Location = System::Drawing::Point(32,16);

this->label2->Name = S"label2";

this->label2->Size = System::Drawing::Size(208, 23);

this->label2->TabIndex = 6;

this->label2->Text = S"XXXX";

}
You don't indicate the issue you're having, but I think I can guess (if
you're using VS 2005).
If you're getting a syntax error on the line:

this->label2->Text = S"XXXX";

that says:

error C3921: Use of S-prefixed strings requires /clr:oldSyntax command line
option

simply remove the "S"

this->label2->Text = "XXXX";
 
Allen Maki said:
Hi Everybody,



I am new to Famework Programming and I need your help.



In Visual C++ .NET

Forms.

Labels.
<snip>

Oops!
My first response is inadequate. I now realize that you're trying to create
the label programatically as well as assign a value to the test property.
Using this code, I now see your issue. My label does appear.
private: System::Windows::Forms::Label^ label2;

void InitializeComponent(void)

{

...

this->label2 = (gcnew System::Windows::Forms::Label());

this->SuspendLayout();



this->label2->AutoSize = false;

this->label2->BorderStyle =
System::Windows::Forms::BorderStyle::FixedSingle;

this->label2->Location = System::Drawing::Point(95, 151);

this->label2->Name = L"label1";

this->label2->Size = System::Drawing::Size(50, 15);

this->label2->TabIndex = 1;

this->Controls->Add(this->label2);

....

}



Later in an event procedure:

this->label2->Text = "XXXX";



This works fine.
 
Hi pvdg42,

I have here both the of the codes. Can you show how to do the changes ?







this->label2->AutoSize = true;

this->label2->Font = new System::Drawing::Font(S"Verdana", 16,
System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,
(System::Byte)0);

this->label2->Image = (__try_cast<System::Drawing::Image *
(resources->GetObject(S"label1.Image")));

this->labe21->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;

this->label2->Location = System::Drawing::Point(8, 112);

this->label2->Name = S"label1";

this->label2->Size = System::Drawing::Size(277, 29);

this->label2->TabIndex = 2;

this->label2->Text = S" Time Tracking System";







private: System::Void label2_Click(System::Object * sender,
System::EventArgs * e)

{

this->label2->Text = S"XXXX";

}
 
Back
Top