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
  1. Home
  2. General Programming
  3. C#
  4. Multiple Instance form

Multiple Instance form

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 4 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.
  • A Offline
    A Offline
    adrian00i
    wrote on last edited by
    #1

    i would like to know if its possible to open 2 or more similar form without changing the opened form parameter as example existing form opened int value is 123, after opening another similar form, int is set to 456 but i do not want it changed in the previos opened form. hope u get what i mean.

    J A L 3 Replies Last reply
    0
    • A adrian00i

      i would like to know if its possible to open 2 or more similar form without changing the opened form parameter as example existing form opened int value is 123, after opening another similar form, int is set to 456 but i do not want it changed in the previos opened form. hope u get what i mean.

      J Offline
      J Offline
      JF2015
      wrote on last edited by
      #2

      Hi, this is quite simple. Normally if you open a second instance of the form, the content of the first form is not modified. If it is, you are accessing a static object or some other shared resource. Here is some code that opens two instances of the same form (Form2) when clicking a button.

      private void button1_Click(object sender, EventArgs e)
      {
      Form2 frm2_1 = new Form2();
      frm2_1.Show();
      Form2 frm2_2 = new Form2();
      frm2_2.Show();
      }

      1 Reply Last reply
      0
      • A adrian00i

        i would like to know if its possible to open 2 or more similar form without changing the opened form parameter as example existing form opened int value is 123, after opening another similar form, int is set to 456 but i do not want it changed in the previos opened form. hope u get what i mean.

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        Overload the form constructor to pass in the count value e.g.

        public frm(int count)
        {
        InitializeComponent();

        //Do whatever with count
        }

        This way, every form instance will be responsible for handling the count value on its own.

        1 Reply Last reply
        0
        • A adrian00i

          i would like to know if its possible to open 2 or more similar form without changing the opened form parameter as example existing form opened int value is 123, after opening another similar form, int is set to 456 but i do not want it changed in the previos opened form. hope u get what i mean.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Forms are just classes; you can instantiate them as often as you like; and no fields get shared between instances unless they are marked static. :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          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