Modal Form Manipulation, C# Express

Need help with modal forms in C#

Page 1 of 1

6 Replies - 2831 Views - Last Post: 09 November 2009 - 09:42 PM Rate Topic: -----

#1 efficacious   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 09-November 09

Modal Form Manipulation, C# Express

Post icon  Posted 09 November 2009 - 06:45 PM

Hi everyone!

I'm writing a simple database send and recieve app and I've gotten myself stuck.

I've set up the program so that on first run a "Setup Wizard" pops up and your asked to fill in
the settings for your database. ie; server, user, pass, DB, ect...

The problem I'm facing is that when I pop up the Wizard form.
I don't want the user to be able to do anything else off that form.

Now at first read you think.. I just need me a modal form.

The code used to show the form is

WizardForm.ShowDialog(this);


On the form I have 4-5 Labels and TxtBoxes.
For the user to enter in the information.

When the form is first loaded the program checks for these values in
the application configuration file. And loads the text (if any) into the text boxes.

I'm trying to give this form a "Reset" button so that if the user makes a mistake.
They can set the textbox values back to what they were when the form first loaded.

However since this form is a Modal form when I click the reset button. Instead of resetting the textboxes
it actually closes the form.

Now if I instead use the code
WizardForm.Show(this);


Then the textboxes do indeed get updated. And the form doesn't close.


The code used to update the textboxes:
			
DataSource_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["DataSource"];
User_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["UserID"];
Pass_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["Pass"];
DB_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["DB"];


I've tried doing this several different ways that I knew of or could find.
Any help or suggestions regarding this issue are greatly appreciated.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Modal Form Manipulation, C# Express

#2 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Modal Form Manipulation, C# Express

Posted 09 November 2009 - 07:14 PM

What's the code you use in your button handler?
Was This Post Helpful? 0
  • +
  • -

#3 efficacious   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 09-November 09

Re: Modal Form Manipulation, C# Express

Posted 09 November 2009 - 07:23 PM

The code is inside my post above.

The "Reset" btn code is :

DataSource_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["DataSource"];
User_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["UserID"];
Pass_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["Pass"];
DB_txtbx.Text = System.Configuration.ConfigurationSettings.AppSettings["DB"];



I'm not sure if this requires a redraw of the form or not but when I open form as modeless using
WizardForm.Show();

Everything works as should. Except for the fact that users can now access other controls on the parent form.

This post has been edited by efficacious: 09 November 2009 - 07:55 PM

Was This Post Helpful? 0
  • +
  • -

#4 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Modal Form Manipulation, C# Express

Posted 09 November 2009 - 08:26 PM

Add a Form.Closing event handler and set the FormClosingEventArgs.Cancel to true.
Was This Post Helpful? 0
  • +
  • -

#5 efficacious   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 09-November 09

Re: Modal Form Manipulation, C# Express

Posted 09 November 2009 - 08:41 PM

I've added the event handler for the form closing but How do I change the FormClosingEventArgs?

	 private void WizardForm_FormClosing(object sender, FormClosingEventArgs e)
		{
   
		}


Was This Post Helpful? 0
  • +
  • -

#6 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Modal Form Manipulation, C# Express

Posted 09 November 2009 - 09:08 PM

private void WizardForm_FormClosing(object sender, FormClosingEventArgs e) {
	e.Cancel = true;
}

Was This Post Helpful? 1
  • +
  • -

#7 efficacious   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 09-November 09

Re: Modal Form Manipulation, C# Express

Posted 09 November 2009 - 09:42 PM

ah *facepalm* nice tyvm

This works perfectly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1