Click here to Skip to main content
15,894,460 members
Home / Discussions / C#
   

C#

 
GeneralRe: waitforexit doesn't wait Pin
thepersonof28-Jun-05 10:04
thepersonof28-Jun-05 10:04 
GeneralRe: waitforexit doesn't wait Pin
Dave Kreskowiak28-Jun-05 15:41
mveDave Kreskowiak28-Jun-05 15:41 
GeneralRe: waitforexit doesn't wait Pin
thepersonof29-Jun-05 8:06
thepersonof29-Jun-05 8:06 
GeneralEasy Forms Question Pin
mikemmmmmm28-Jun-05 6:39
mikemmmmmm28-Jun-05 6:39 
GeneralRe: Easy Forms Question Pin
Anonymous28-Jun-05 6:54
Anonymous28-Jun-05 6:54 
GeneralRe: Easy Forms Question Pin
Matt Gerrans28-Jun-05 9:07
Matt Gerrans28-Jun-05 9:07 
GeneralRe: Easy Forms Question Pin
mikemmmmmm28-Jun-05 11:41
mikemmmmmm28-Jun-05 11:41 
GeneralRe: Easy Forms Question Pin
Matt Gerrans28-Jun-05 14:20
Matt Gerrans28-Jun-05 14:20 
Here's a minimal example, without validation, etc.

Snippet from the main form (extraneous stuff omitted):

class MainForm : Form
{
    private string chosenPizza = "Pepperoni";
    private bool cheesy = true;

    private void buttonChooseNewPizza_Click(object sender, EventArgs e)
    {
        PizzaOrderForm orderForm = new PizzaOrderForm();
        orderForm.PizzaType = chosenPizza;
        orderForm.Cheesy = cheesy;
        DialogResult answer = orderForm.ShowDialog(this);
        if (answer == DialogResult.OK)
        {
            chosenPizza = orderForm.PizzaType;
            cheesy = orderForm.Cheesy;
            labelOrderStatus.Text = "Your " + chosenPizza + " pizza with" +
                                    (cheesy ? "" : "out") + 
                                    " cheese is coming right up!";
        }
    }
}


And from the sub-dialog form:
partial class PizzaOrderForm : Form
{
  public PizzaOrderForm()
  {
     InitializeComponent();
  }

  private string pizzaType;
  public string PizzaType
  {
     get
     {
        return pizzaType;
     }
     set
     {
        switch (value.ToLower())
        {
           case "pepperoni":
           case "hawaiian":
           case "vegetarian":
              pizzaType = value;
              break;
           default:
              throw new ArgumentOutOfRangeException(string.Format("Sorry, {0} pizza is not on the menu.", value ));
        }
     }
  }
  private bool cheesy = true;
  public bool Cheesy
  {
     get
     {
        return cheesy;
     }
     set
     {
        cheesy = value;
     }
  }

  private void PizzaOrderForm_Load(object sender, EventArgs e)
  {
     textBoxPizza.Text = PizzaType;
     checkBoxCheese.Checked = Cheesy;
  }

  private void buttonOK_Click(object sender, EventArgs e)
  {
     PizzaType = textBoxPizza.Text;
     Cheesy = checkBoxCheese.Checked;
  }
}

Also, the OK and Cancel button's DialogResult properties should be set accordingly.

(If you're using .NET 1.0 or before, don't be confounded by the partial class, it just lets the form designer do all its code generation in a separate file).

Matt Gerrans
GeneralRe: Easy Forms Question Pin
Anonymous28-Jun-05 20:12
Anonymous28-Jun-05 20:12 
GeneralRe: Easy Forms Question Pin
Matt Gerrans29-Jun-05 5:30
Matt Gerrans29-Jun-05 5:30 
GeneralSetup File Pin
Yigal Agam28-Jun-05 6:30
Yigal Agam28-Jun-05 6:30 
GeneralRe: Setup File Pin
Nick Parker28-Jun-05 9:54
protectorNick Parker28-Jun-05 9:54 
GeneralRe: Setup File Pin
Yigal Agam28-Jun-05 10:02
Yigal Agam28-Jun-05 10:02 
GeneralContext Menu Pin
Yigal Agam28-Jun-05 6:28
Yigal Agam28-Jun-05 6:28 
GeneralAnother interesting fact Pin
Yigal Agam6-Jul-05 3:58
Yigal Agam6-Jul-05 3:58 
QuestionHow can I download gif-file from internet (URL) in C# Pin
frada28-Jun-05 5:49
frada28-Jun-05 5:49 
AnswerRe: How can I download gif-file from internet (URL) in C# Pin
rwanderson28-Jun-05 7:56
rwanderson28-Jun-05 7:56 
GeneralRe: How can I download gif-file from internet (URL) in C# Pin
eggie528-Jun-05 9:57
eggie528-Jun-05 9:57 
GeneralRe: How can I download gif-file from internet (URL) in C# Pin
frada28-Jun-05 10:01
frada28-Jun-05 10:01 
GeneralChecking if a value is an integer Pin
Andy *M*28-Jun-05 5:08
Andy *M*28-Jun-05 5:08 
GeneralRe: Checking if a value is an integer Pin
User 665828-Jun-05 5:32
User 665828-Jun-05 5:32 
GeneralRe: Checking if a value is an integer Pin
Andy *M*28-Jun-05 6:14
Andy *M*28-Jun-05 6:14 
GeneralRe: Checking if a value is an integer Pin
Andy *M*29-Jun-05 3:05
Andy *M*29-Jun-05 3:05 
GeneralRe: Checking if a value is an integer Pin
mav.northwind28-Jun-05 5:57
mav.northwind28-Jun-05 5:57 
GeneralRe: Checking if a value is an integer Pin
Andy *M*28-Jun-05 6:26
Andy *M*28-Jun-05 6:26 

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.