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. all form problem? [modified]

all form problem? [modified]

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 1 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?

    modified on Sunday, January 10, 2010 1:38 AM

    OriginalGriffO 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?

      modified on Sunday, January 10, 2010 1:38 AM

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

      Firstly: Don't do it! If you access controls on one form from another, then you are locking the design of teh two forms together - you cannot change one form without changing the other. This defeats one of the intentions of an OOP language at a stroke, and it why by default controls are not declared as public. Instead, either: 1) Set up a public property or method on form2 which form1 can access to get the information it needs without knowning the internal details of form2. or 2) Set up an event or delegate with form1 can subscribe to get the information. Depending on what you are doing when you need the information will determine which way to go. If you need form1 to be aware when the datetimepicker has changed, then use (2), otherwise, go with (1).

      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
      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