form refresh or make duplicates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dcurvez
    New Member
    • Apr 2010
    • 5

    form refresh or make duplicates

    hi all :)

    got question on using windows forms in visual

    what i have going on is on one form i have a calendar that is for the month of may. when you click on may 1...it opens a form with some combo boxes and a gridview that displays the choices from the combo boxes.

    my question is this..
    can I just link all of the other 30 days in may to go to the same form or do I have to make 30 duplicate forms LOL...i know it is a kinda silly question but I really dont know.

    It would be a travesty if the user were to click on may 2...and get a form all filled out from may 1...*blush*

    Secondly if i were to have a calendar control on the form that may 1 is pointing to (at the moment I dont) how do I get the calendar contol to reflect that it is may 2 and not may 1??

    this is not for a web site it is for a tire shop here in town, and it is the first project that I am doing..so it is kind of important to me.

    thanks all :)
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Originally posted by OriginalPoster
    How do I get my Form2 to react to something on my Form1?
    How do I make my Form1 control something on my Form2?
    Although you can have Form1 directly access items on Form2 it isn't the recommended way to go. It ties the two forms tightly to each other. If a change is made in Form2 such as removing one of the controls, then code in Form1 breaks.
    It is better to Form1 raise an event, and have Form2 contain its own code for how to react to this. This places responsibility for Form2 within Form2, and Form1 within Form1.
    It keeps Form1 blissfully ignorant of Form2 - and a logging component - and a progress component, and a dozen other little black boxes that can be subscribed to events in Form1, all without Form1 being made responsible for directly affecting controls other than itself.
    Events tutorial (including Form to Form which is the same as class to class)
    This tutorial for a cash register does exactly that: It makes a virtual numeric keyboard.

    Bad: Directly accessing controls of one class/form from another.
    Code:
    bool IsOn = Form2.button1.IsChecked;
    Good: Use a property to get such information
    Code:
    //Form1
    bool IsOn = Form2.IsOn;
    Code:
    //Form 2
    public bool IsOn
    {
       get { return CheckBox1.Checked; }
       set { CheckBox1.Checked = value; }
    }
    It's a subtle but important difference as your applications become more complex. Using properties means your target class/form (Form2) can be changed and updated a thousand different ways yet won't negatively impact the classes that are reading from it. If you change the name of a control for example: It won't break references in all your other classes. If your target form evolves where it needs to do 10 things when it is turned on, then the responsibility stays within Form2, and that burden is not put on Form1 and a dozen other forms that might be using Form2. The goal is to compartimentali ze the work so that Form2 is responsiblity SOLELY for Form2. From1 should only have to say "Turn on" or "Turn Off"

    Form2
    Code:
    public bool IsOn
    {
       get { return btnMeaningfulName.Checked; }
       set {
                btnMeaningfulName.Checked = value;
                panelDashboard.Visible = value;
                labelStatus = value == true ? "On" : "Off";
                btnRunNow.Enabled = value;
           }
    }
    Now when Form1 tells Form2 to turn on, Form2 will check a box, make an entire panel visible, change its Status label to say 'On' and enable a Run Now button.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Basically you make instances of forms.

      So your 'EnterDetailsFo rThisDate" form is the form TYPE.
      Each time you click on a date in your calendar you open a new INSTANCE of that form.

      <click on date>
      Code:
      DateDetailsForm myNewDateDetails = new DateDetailsForm();

      Comment

      • Dcurvez
        New Member
        • Apr 2010
        • 5

        #4
        okay I will go and read this tutorial

        okay :) I will go and read the tutorial and see if I can make it work.

        I do understand what your telling me,, as I can relate it too having all your eggs in one basket sort of deal.

        thank you for your detailed response :)

        Comment

        Working...