Click here to Skip to main content
15,912,897 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionLPCTSTR problem Pin
Xeronith10-Dec-05 19:10
Xeronith10-Dec-05 19:10 
AnswerRe: LPCTSTR problem Pin
Nemanja Trifunovic11-Dec-05 3:05
Nemanja Trifunovic11-Dec-05 3:05 
AnswerRe: LPCTSTR problem Pin
Jörgen Sigvardsson11-Dec-05 12:52
Jörgen Sigvardsson11-Dec-05 12:52 
Questionservices in Windows Server 2003 OS Pin
Thomas_Mathews8-Dec-05 23:30
Thomas_Mathews8-Dec-05 23:30 
AnswerRe: services in Windows Server 2003 OS Pin
Sheng Jiang 蒋晟11-Dec-05 11:03
Sheng Jiang 蒋晟11-Dec-05 11:03 
GeneralRe: services in Windows Server 2003 OS Pin
Thomas_Mathews11-Dec-05 18:44
Thomas_Mathews11-Dec-05 18:44 
GeneralRe: services in Windows Server 2003 OS Pin
Thomas_Mathews11-Dec-05 19:34
Thomas_Mathews11-Dec-05 19:34 
QuestionHalting execution until a button is clicked Pin
Simon Cornish8-Dec-05 6:33
Simon Cornish8-Dec-05 6:33 
I am new to windows programming, and am using Visual Studio .Net 2003.

I have a standard managed form which contains a number of data entry fields (textboxes, radio buttons etc), and a couple of buttons.

One of the buttons (labelled Save) activates an event handler that calls two functions. The first function will perform some validation on the data entered in the form, and then displays a message on a second smaller form with an OK button. This OK button closes the form. The second function then formats some of the data, and will eventually write it to a file.

How do I stop the second function running until after the OK button on the form displayed by the first function is clicked ? Or, in other words, how do I stop the 2nd function from running until the first is complete.

The program so far is listed below, and the event handler concerned is called collegeForm::buttonSave.

Many thanks

#using
#using
#using
#using

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

__gc class collegeForm : public Form
{
public :
collegeForm();

private :
Label *labelSurname;
Label *labelForename;
Label *labelGender;
Label *labelDateOfBirth;
Label *labelAccomodation;
Label *labelSupportCode;
Label *labelCourseCode;

TextBox *surname;
TextBox *forename;
TextBox *courseCode;
TextBox *dateOfBirth;

ComboBox *supportCode;

GroupBox *gender;
RadioButton *male;
RadioButton *female;

GroupBox *accomodation;
RadioButton *parentalHome;
RadioButton *lodgings;
RadioButton *hallsOfResidence;

Button *save;
Button *clear;

MainMenu * mainMenu;

void buttonSave(Object *Sender, EventArgs *Args);
void buttonClear(Object *Sender, EventArgs *Args);
Int32 validateForm(void);
void formatNames(void);
};

__gc class errorMessage : public Form
{
public :
errorMessage();
errorMessage(String *);

private :
Label *message;
Button *ok;

void buttonOK(Object *Sender, EventArgs *Args);
};

errorMessage::errorMessage()
{
}

errorMessage::errorMessage(String * errorMessage)
{
this->Text = S"Error Message";
message = new Label;
message->Text = errorMessage;
message->Location = Point(25,100);
this->Controls->Add(message);

ok = new Button;
ok->Location = Point(180,120);
ok->Text = "OK";
ok->Click += new EventHandler(this,buttonOK);
this->Controls->Add(ok);
}

void errorMessage::buttonOK(Object *Sender, EventArgs *Args)
{
Close();
}


collegeForm::collegeForm()
{
this->Text = S"College Enrollment Database";

labelSurname = new Label;
labelSurname->Text = S"Surname";
labelSurname->Location = Point(25,100);
this->Controls->Add(labelSurname);

labelForename = new Label;
labelForename->Text = S"Forename";
labelForename->Location = Point(25,150);
this->Controls->Add(labelForename);

labelGender = new Label;
labelGender->Text = S"Gender";
labelGender->Location = Point(25,200);
this->Controls->Add(labelGender);

labelDateOfBirth = new Label;
labelDateOfBirth->Text = S"Date Of Birth";
labelDateOfBirth->Location = Point(25,250);
this->Controls->Add(labelDateOfBirth);

labelAccomodation = new Label;
labelAccomodation->Text = S"Accomodation";
labelAccomodation->Location = Point(25,300);
this->Controls->Add(labelAccomodation);

labelSupportCode = new Label;
labelSupportCode->Text = S"Support Code";
labelSupportCode->Location = Point(25,350);
this->Controls->Add(labelSupportCode);

labelCourseCode = new Label;
labelCourseCode->Text = S"Course Code";
labelCourseCode->Location = Point(25,400);
this->Controls->Add(labelCourseCode);

surname = new TextBox;
surname->Location = Point(125,100);
surname->Width = 200;
this->Controls->Add(surname);

forename = new TextBox;
forename->Location = Point(125,150);
forename->Width = 200;
this->Controls->Add(forename);

courseCode = new TextBox;
courseCode->Location = Point(125,400);
courseCode->Width = 100;
this->Controls->Add(courseCode);

dateOfBirth = new TextBox;
dateOfBirth->Location = Point(125,250);
dateOfBirth->Width = 200;
this->Controls->Add(dateOfBirth);

supportCode = new ComboBox;
supportCode->Location = Point(125,350);
supportCode->Width = 230;
supportCode->Items->Add(S"No Known Disability");
supportCode->Items->Add(S"Dyslexia");
supportCode->Items->Add(S"Blind or Partially Sighted");
supportCode->Items->Add(S"Deaf or Impaired Hearing");
supportCode->Items->Add(S"Mobility Difficulties or Wheelchair User");
supportCode->Items->Add(S"Personal Care Support Required");
supportCode->Items->Add(S"Mental Health Difficulties");
supportCode->Items->Add(S"Unseen Disability - Diabetes, Asthma");
supportCode->Items->Add(S"Two Or More Of The Above");
supportCode->Items->Add(S"Other Disability Not Listed");
supportCode->Text = S"No Known Disability";
this->Controls->Add(supportCode);

gender = new GroupBox;
gender->Location = Point(125,175);
gender->Size = Drawing::Size(300,55);
Controls->Add(gender);

male = new RadioButton;
male->Location = Point(25,20); // These are coords in group box
male->Text = S"Male";
gender->Controls->Add(male);

female = new RadioButton;
female->Location = Point(150,20);
female->Text = S"Female";
gender->Controls->Add(female);

accomodation = new GroupBox;
accomodation->Location = Point(125,275);
accomodation->Size = Drawing::Size(450,55);
Controls->Add(accomodation);

parentalHome = new RadioButton;
parentalHome->Location = Point(25,20);
parentalHome->Text = S"&Parental Home";
accomodation->Controls->Add(parentalHome);

lodgings = new RadioButton;
lodgings->Location = Point(150,20);
lodgings->Text = S"Lodgings";
accomodation->Controls->Add(lodgings);

hallsOfResidence = new RadioButton;
hallsOfResidence->Location = Point(275,20);
hallsOfResidence->Text = S"&Halls Of Residence";
accomodation->Controls->Add(hallsOfResidence);

save = new Button;
save->Location = Point(175,500);
save->Text = S"&Save";
save->Click += new EventHandler(this,buttonSave);
this->Controls->Add(save);

clear = new Button;
clear->Location = Point(350,500);
clear->Text = S"&Clear";
clear->Click += new EventHandler(this,buttonClear);
this->Controls->Add(clear);

mainMenu = new MainMenu();
MenuItem *menuFile = mainMenu->MenuItems->Add("&File");
menuFile->MenuItems->Add("&Validate");
menuFile->MenuItems->Add("&Save");
menuFile->MenuItems->Add("&Clear");
menuFile->MenuItems->Add("-");
menuFile->MenuItems->Add("&Exit");

MenuItem *menuHelp = mainMenu->MenuItems->Add("&Help");
menuHelp->MenuItems->Add("&About");

Menu = mainMenu;

}

void collegeForm::buttonSave(Object *Sender, EventArgs *Args)
{
validateForm();
formatNames();
}

void collegeForm::buttonClear(Object *Sender, EventArgs *Args)
{
surname->Text = S"";
forename->Text = S"";
courseCode->Text = S"";
dateOfBirth->Text = S"";
supportCode->Text = S"";
male->Checked = false;
female->Checked = false;
parentalHome->Checked = false;
lodgings->Checked = false;
hallsOfResidence->Checked = false;
}

Int32 collegeForm::validateForm(void)
{
errorMessage * em = new errorMessage("This is a test");
em->Size = System::Drawing::Size(400,200);
em->Show();
return(1);
}

void collegeForm::formatNames(void)
{
String * left;
String * right;
String * temp;

if (surname->Text->Length > 1)
{
temp = surname->Text;
left = temp->Substring(0,1);
right = temp->Substring(1,temp->Length-1);
left = left->ToUpper();
right = right->ToLower();
temp = String::Concat(left,right);
surname->Text = temp;
}

if (forename->Text->Length > 1)
{
temp = forename->Text;
left = temp->Substring(0,1);
right = temp->Substring(1,temp->Length-1);
left = left->ToUpper();
right = right->ToLower();
temp = String::Concat(left,right);
forename->Text = temp;
}
}

int __stdcall WinMain()
{
collegeForm *cf = new collegeForm();
cf->Size = System::Drawing::Size(600,600);
Application::Run(cf);
return 0;
}

Simon Cornish


Simon Cornish
AnswerRe: Halting execution until a button is clicked Pin
Saksida Bojan8-Dec-05 19:52
Saksida Bojan8-Dec-05 19:52 
GeneralRe: Halting execution until a button is clicked Pin
Simon Cornish8-Dec-05 21:21
Simon Cornish8-Dec-05 21:21 
Questionlinking assembly dll to project Pin
9ine7-Dec-05 3:46
9ine7-Dec-05 3:46 
AnswerRe: linking assembly dll to project Pin
Nish Nishant7-Dec-05 4:03
sitebuilderNish Nishant7-Dec-05 4:03 
GeneralRe: linking assembly dll to project Pin
9ine7-Dec-05 5:24
9ine7-Dec-05 5:24 
GeneralRe: linking assembly dll to project Pin
Nish Nishant7-Dec-05 7:12
sitebuilderNish Nishant7-Dec-05 7:12 
GeneralRe: linking assembly dll to project Pin
Saksida Bojan7-Dec-05 19:56
Saksida Bojan7-Dec-05 19:56 
GeneralRe: linking assembly dll to project Pin
9ine7-Dec-05 22:09
9ine7-Dec-05 22:09 
QuestionHelp please with Skip List Pin
Reunion7-Dec-05 2:00
Reunion7-Dec-05 2:00 
AnswerRe: Help please with Skip List Pin
Nish Nishant7-Dec-05 4:02
sitebuilderNish Nishant7-Dec-05 4:02 
AnswerRe: Help please with Skip List Pin
Blake Miller7-Dec-05 9:33
Blake Miller7-Dec-05 9:33 
GeneralRe: Help please with Skip List Pin
Reunion7-Dec-05 19:47
Reunion7-Dec-05 19:47 
Questionwho can help me design this project Pin
chen10006-Dec-05 15:22
chen10006-Dec-05 15:22 
AnswerRe: who can help me design this project Pin
chen10006-Dec-05 15:29
chen10006-Dec-05 15:29 
AnswerRe: who can help me design this project Pin
toxcct6-Dec-05 21:45
toxcct6-Dec-05 21:45 
JokeRe: who can help me design this project Pin
Nish Nishant7-Dec-05 0:12
sitebuilderNish Nishant7-Dec-05 0:12 
Question"EXPORTING STATIC AND NON-MEMBER FUNCTIONS Pin
barry1234-Dec-05 20:42
barry1234-Dec-05 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.