Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. call Form problem!!

call Form problem!!

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss YY
    wrote on last edited by
    #1

    Now i have form1 and form2 datetimepicker1 and datetimepicker2 is in form1 i want to use datetimepicker1 and datetimepicker2 on form2 from form1,set datetimepicker1'modifiers and datetimepicker2'MOdifiers to public on form1, i wrote my code on form1 like this string from, to; from = this.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = this.dateTimePicker2.Value.ToString("yyyy-MM-dd"); it can work very well then wrote my code on form2 like this Form1 frm=new Form1(); string from, to; from = frm.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = frm.dateTimePicker2.Value.ToString("yyyy-MM-dd"); when i run my code ,from=2010-01-09,to=2010-01-09 on form2 but when i select dateTimePicker1=2010-01-05, dateTimePicker2=2010-01-09 on form1, then run my code ,it shows from=2010-01-05,to=2010-01-09 on form1,but it also shows from=2010-01-09,to=2010-01-09 on form2,it do not change anymore on form2,i think it may be read from the most beginning. i want to get the changed dateTimePicker.Value,how could i do thanks everyone?

    R D OriginalGriffO realJSOPR 4 Replies Last reply
    0
    • M miss YY

      Now i have form1 and form2 datetimepicker1 and datetimepicker2 is in form1 i want to use datetimepicker1 and datetimepicker2 on form2 from form1,set datetimepicker1'modifiers and datetimepicker2'MOdifiers to public on form1, i wrote my code on form1 like this string from, to; from = this.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = this.dateTimePicker2.Value.ToString("yyyy-MM-dd"); it can work very well then wrote my code on form2 like this Form1 frm=new Form1(); string from, to; from = frm.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = frm.dateTimePicker2.Value.ToString("yyyy-MM-dd"); when i run my code ,from=2010-01-09,to=2010-01-09 on form2 but when i select dateTimePicker1=2010-01-05, dateTimePicker2=2010-01-09 on form1, then run my code ,it shows from=2010-01-05,to=2010-01-09 on form1,but it also shows from=2010-01-09,to=2010-01-09 on form2,it do not change anymore on form2,i think it may be read from the most beginning. i want to get the changed dateTimePicker.Value,how could i do thanks everyone?

      R Offline
      R Offline
      Roger Wright
      wrote on last edited by
      #2

      Can you post the actual code, rather than your synopsis? I have some thoughts about what may be happenning, but I don't want to lead you astray by guessing. Copy and paste the code for both forms in your reply, then highlight all of it and click the

      code block

      tag above to preserve your formatting.

      "A Journey of a Thousand Rest Stops Begins with a Single Movement"

      1 Reply Last reply
      0
      • M miss YY

        Now i have form1 and form2 datetimepicker1 and datetimepicker2 is in form1 i want to use datetimepicker1 and datetimepicker2 on form2 from form1,set datetimepicker1'modifiers and datetimepicker2'MOdifiers to public on form1, i wrote my code on form1 like this string from, to; from = this.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = this.dateTimePicker2.Value.ToString("yyyy-MM-dd"); it can work very well then wrote my code on form2 like this Form1 frm=new Form1(); string from, to; from = frm.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = frm.dateTimePicker2.Value.ToString("yyyy-MM-dd"); when i run my code ,from=2010-01-09,to=2010-01-09 on form2 but when i select dateTimePicker1=2010-01-05, dateTimePicker2=2010-01-09 on form1, then run my code ,it shows from=2010-01-05,to=2010-01-09 on form1,but it also shows from=2010-01-09,to=2010-01-09 on form2,it do not change anymore on form2,i think it may be read from the most beginning. i want to get the changed dateTimePicker.Value,how could i do thanks everyone?

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        miss YY wrote:

        set datetimepicker1 and datetimepicker2 modifiers to public on form1

        Not necessary and not a good idea

        miss YY wrote:

        on form2 like this Form1 frm = new Form1();

        This is the clue! This is a new instance of Form1 (i.e. not the same one as you are viewing) so the DateTimePickers are not the same ones and therefore have different values. Where is form2 created - in Form1? If so, keep a reference in Form1 to the new Form2. In Form2, create properties or methods to receive the DateTimes, and set them from Form1 when they change using the reference you already have.

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        1 Reply Last reply
        0
        • M miss YY

          Now i have form1 and form2 datetimepicker1 and datetimepicker2 is in form1 i want to use datetimepicker1 and datetimepicker2 on form2 from form1,set datetimepicker1'modifiers and datetimepicker2'MOdifiers to public on form1, i wrote my code on form1 like this string from, to; from = this.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = this.dateTimePicker2.Value.ToString("yyyy-MM-dd"); it can work very well then wrote my code on form2 like this Form1 frm=new Form1(); string from, to; from = frm.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = frm.dateTimePicker2.Value.ToString("yyyy-MM-dd"); when i run my code ,from=2010-01-09,to=2010-01-09 on form2 but when i select dateTimePicker1=2010-01-05, dateTimePicker2=2010-01-09 on form1, then run my code ,it shows from=2010-01-05,to=2010-01-09 on form1,but it also shows from=2010-01-09,to=2010-01-09 on form2,it do not change anymore on form2,i think it may be read from the most beginning. i want to get the changed dateTimePicker.Value,how could i do thanks everyone?

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          miss YY wrote:

          Form1 frm=new Form1(); string from, to; from = frm.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = frm.dateTimePicker2.Value.ToString("yyyy-MM-dd");

          Since you haven't shown the form, the user hasn't had a chance to change the values. "new" does exactly that: creates a new instance of Form1. If you have an existing instance of Form1 that the user has allready selected the to and from dates on, you need to access that instead.

          All those who believe in psycho kinesis, raise my hand.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • M miss YY

            Now i have form1 and form2 datetimepicker1 and datetimepicker2 is in form1 i want to use datetimepicker1 and datetimepicker2 on form2 from form1,set datetimepicker1'modifiers and datetimepicker2'MOdifiers to public on form1, i wrote my code on form1 like this string from, to; from = this.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = this.dateTimePicker2.Value.ToString("yyyy-MM-dd"); it can work very well then wrote my code on form2 like this Form1 frm=new Form1(); string from, to; from = frm.dateTimePicker1.Value.ToString("yyyy-MM-dd"); to = frm.dateTimePicker2.Value.ToString("yyyy-MM-dd"); when i run my code ,from=2010-01-09,to=2010-01-09 on form2 but when i select dateTimePicker1=2010-01-05, dateTimePicker2=2010-01-09 on form1, then run my code ,it shows from=2010-01-05,to=2010-01-09 on form1,but it also shows from=2010-01-09,to=2010-01-09 on form2,it do not change anymore on form2,i think it may be read from the most beginning. i want to get the changed dateTimePicker.Value,how could i do thanks everyone?

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            Create a static class that holds the DateTime objects, and simply refer to them from both forms.

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups