Forms and Labels

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

Allen Maki

I wonder if you could help.

The event handler code below, will allow the user to change the phone number
and write it on a label of a message box. I want to replace the message box
with a dialog box.

Can anybody help me replace the message box below to a dialog box. In other
words. I want to write the new phone number on a label (named "labe1")of a
dialog box (named "dialog2),instead of writing the new phone number on the
label of a message box.

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

{

// Create the dialog

MyDialog* box = new MyDialog();


//Fill in the initial data

box->Phone = S"(650)123-3456)"; // <------ This is the phone number to be
changed

//Show dialog

if (box->ShowDialog() == DialogResult::OK)

{

MessageBox::Show(box->Phone); //<-----I tried to change this line


}

}
 
Is this what you are looking for?

if (box->ShowDialog() == DialogResult::OK)
{
MyDialog* dialog2 = new MyDialog();
dialog2->label1->Text = box->Phone;
dialog2->ShowDialog();
}
 
Hi,

I think the question was how to manial position the message box and the
answer AFAIK is - you can't.
You cannot sepcify the location of the dialog box.

What you can do though is to use you custom dialog box as Bryan suggested
and set its StartPosition to *Manual* and then place it at the location you
need.
 
Hi Bryant,



I really appreciate you taking the time to help.



I did what you told me and I got the error message below:



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

{

MyDialog *box =new MyDialog();

box->Phone = S"650 123 3456";



if (box->ShowDialog() == DialogResult::OK)

{

MyDialog* dialog2 = new MyDialog;

dialog2->label1->Text =
box->Phone;//<-----error C2039: 'label1' : is not a

//member of 'CpForm::MyDialog'

dialog2->ShowDialog();



}



}
 
Allen,

When you drop a control on the form such as label generated member (field)
for this control by default is private, so you cannot access it from outside
the class. You should provide a public property for get/set the label text
(preferable) or change the Modifiers property for the control in the
property browser to some less restrictive value such as public or internal
(this option I wouldn't recommend.

HTH
 
Hi Stoitcho,

I have the property all ready:

__property void set_Phone(String* p) {phoneBox->Text = p;}

__property String* get_Phone() {return phoneBox->Text;}

As I said before, this code worked very well with a message box, but I
Wanted it to work with a form and label.

Thanks anyway.
 
Allen,

Excuse me if I don't understand you problem correctly, but I thought the
problem was here

and the error clearly state that you are trying to access the lable (label1)
declared in the MyDialog class and I blieve the label1 member is declared
privately.

Is this the actual problem?
 
Back
Top