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. how to pass a handler to another form

how to pass a handler to another form

Scheduled Pinned Locked Moved C#
helptutorialquestion
10 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.
  • Z Offline
    Z Offline
    zhiyuan16
    wrote on last edited by
    #1

    dear all i am a newbe, this is a basic issue. i want to get a form's width height, and other property in another form. so how i can achive this point? thanks.

    P B L 3 Replies Last reply
    0
    • Z zhiyuan16

      dear all i am a newbe, this is a basic issue. i want to get a form's width height, and other property in another form. so how i can achive this point? thanks.

      P Offline
      P Offline
      phil o
      wrote on last edited by
      #2

      Hi, Your question is not clear. Could you tell us what you've done so far to get what you want, and which issues you encountered ?

      1 Reply Last reply
      0
      • Z zhiyuan16

        dear all i am a newbe, this is a basic issue. i want to get a form's width height, and other property in another form. so how i can achive this point? thanks.

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        One of the ways is: From Form1 get Height and Width of Form2 by:

        Form2 frm2 = new Form2();
        int height = frm2.Height;
        int width = frm2.Width;


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        1 Reply Last reply
        0
        • Z zhiyuan16

          dear all i am a newbe, this is a basic issue. i want to get a form's width height, and other property in another form. so how i can achive this point? thanks.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Assuming you have a reference to the other form then you can access its properties.

          It's time for a new signature.

          Z 1 Reply Last reply
          0
          • L Lost User

            Assuming you have a reference to the other form then you can access its properties.

            It's time for a new signature.

            Z Offline
            Z Offline
            zhiyuan16
            wrote on last edited by
            #5

            thanks first. if i have such dialogs

            InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
            InspectionResultDialog m_RltDlg = new InspectionResultDialog();
            Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();

            i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.

            B L D 3 Replies Last reply
            0
            • Z zhiyuan16

              thanks first. if i have such dialogs

              InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
              InspectionResultDialog m_RltDlg = new InspectionResultDialog();
              Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();

              i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #6

              Then use internal static variables [^]


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

              1 Reply Last reply
              0
              • Z zhiyuan16

                thanks first. if i have such dialogs

                InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
                InspectionResultDialog m_RltDlg = new InspectionResultDialog();
                Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();

                i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Keep the references to your dialogs or forms in your main form class or make them global so that you can refer to them in any module.

                It's time for a new signature.

                Z 1 Reply Last reply
                0
                • Z zhiyuan16

                  thanks first. if i have such dialogs

                  InspectionImageDialog m_ImgDlg = new InspectionImageDialog();
                  InspectionResultDialog m_RltDlg = new InspectionResultDialog();
                  Intel_Amd_InfoDialog intelamdDialog = new Intel_Amd_InfoDialog();

                  i would like to only new once and i can use this instance in anywhere of my project. how to do that? so far, i have 3 forms above and 1 mainDlg, so i want to control 3 dialogs in my mainDlg, also sometimes i want to get some property in other dialog. so how to new a instance and then i can use this instance freely and get its property and asign value or get value there.

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

                  If you want to access an object instance from anywhere, the Singleton pattern[^] is the recommended method. Are you sure you want to do this for three forms though? Static/Singletons have their place and uses but can often be the result of poor design, poor undestanding of OOP, lazyness. I'm not saying "don't", just be sure that it is actually required!

                  Dave

                  If this helped, please vote & accept answer!

                  Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                  1 Reply Last reply
                  0
                  • L Lost User

                    Keep the references to your dialogs or forms in your main form class or make them global so that you can refer to them in any module.

                    It's time for a new signature.

                    Z Offline
                    Z Offline
                    zhiyuan16
                    wrote on last edited by
                    #9

                    how to keep the reference for dialog or forms in my main form class? could u give me an example?thanks

                    L 1 Reply Last reply
                    0
                    • Z zhiyuan16

                      how to keep the reference for dialog or forms in my main form class? could u give me an example?thanks

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      I don't quite understand your problem with this. Just add a variable of the correct form type to your main form, create the new form and save the reference. You could do this in your constructor or create a special method that does it on demand; either way your other forms will remain until you destroy them. Then you can use that from anywhere in your main form code.

                      It's time for a new signature.

                      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