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. Visual Basic
  4. Calling properties of one Form1 into another Form2.

Calling properties of one Form1 into another Form2.

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
14 Posts 6 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.
  • J jeshra279

    My implelentation is like this: In Form1, Code is: Sub Functioname() { GroupbBox1.Enabled = False } Now I want to enable this GroupBox1 through Form2 in following function: Sub FunctionEnable() { ''''' Code will come here } Please let me know how to call that GroupBox1 control so that I can use its properties in Form2. Regards R.S.

    J Offline
    J Offline
    Johan Hakkesteegt
    wrote on last edited by
    #5

    See the other reply to your question. P.S. Besides that it seems you are on the wrong forum.

    My advice is free, and you may get what you paid for.

    1 Reply Last reply
    0
    • D DaveAuld

      You cannot Enable / Disbale a tab directly. It does not have a property for this. The recommended method on MSDN is to handle the TabControl SelectedIndexChanged event. you will need to have a flag somewhere that you can set to reflect the state of the tab (enabled/Disabled) and then check in this event which tab you are on and then move to another tab if you try to select it when it is disabled. Search google for "How to: Disable Tab Pages" and you will find the article at MSDN. Dave

      Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #6

      Actually, you can disable tab pages. Read this[^] thread.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      D 1 Reply Last reply
      0
      • J jeshra279

        My implelentation is like this: In Form1, Code is: Sub Functioname() { GroupbBox1.Enabled = False } Now I want to enable this GroupBox1 through Form2 in following function: Sub FunctionEnable() { ''''' Code will come here } Please let me know how to call that GroupBox1 control so that I can use its properties in Form2. Regards R.S.

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #7

        Do you have a reference to form1 in form2? If you do then just call the Functioname method directly. If not then change your structure to have a reference. If the forms are intrinsically linked like this then there is no point doing this with events.

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

        J 1 Reply Last reply
        0
        • J jeshra279

          Hi All, I have two forms, Form1 and Form2. Form1 has a tab control with tab name "A". I want to enable/disable this tab from Form2. How to do this?

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

          You need a reference for Form1 in Form2 so you can directly manipulate its controls and set its properties.

          J 1 Reply Last reply
          0
          • D dan sh

            Actually, you can disable tab pages. Read this[^] thread.

            50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

            D Offline
            D Offline
            DaveAuld
            wrote on last edited by
            #9

            Didn't know that! Although, i dare say if you are using unsupported methods (or hidden ones) and something breaks folling updates to the api, you don't really have a leg to stand on!

            Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

            1 Reply Last reply
            0
            • L Lost User

              You need a reference for Form1 in Form2 so you can directly manipulate its controls and set its properties.

              J Offline
              J Offline
              jeshra279
              wrote on last edited by
              #10

              Hi Shameel, I am sedning You the actual scenario where I am using multiple forms this: I have 2 forms, main Form1 and a loginform. I made a click event for OK button in loginform, so once user clicks the OK button, I want to call one function which is defined in Form1 as a Public. The code structure is like this: in main Form1, i created a function like this: Class Form1() Public Function DoThis() ....some task... End Function End now in loginform, in the click event for OK button: Class loginform() Click_OK() { DoThis()....call function DoThis() of Form1 } End I am not able to call the DoThis() function in loginform. Please tell me how to do this?? Hope my problem is clear..Thanks.

              L 1 Reply Last reply
              0
              • J jeshra279

                Hi Shameel, I am sedning You the actual scenario where I am using multiple forms this: I have 2 forms, main Form1 and a loginform. I made a click event for OK button in loginform, so once user clicks the OK button, I want to call one function which is defined in Form1 as a Public. The code structure is like this: in main Form1, i created a function like this: Class Form1() Public Function DoThis() ....some task... End Function End now in loginform, in the click event for OK button: Class loginform() Click_OK() { DoThis()....call function DoThis() of Form1 } End I am not able to call the DoThis() function in loginform. Please tell me how to do this?? Hope my problem is clear..Thanks.

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

                To call a function on Form1, you need a reference to the form in your loginform. It depends on where you instantiate Form1 in your app. Assuming that you instantiate Form1 in loginform (since loginform should ideally be the first form that is loaded in your app from main() method), the code could be something like this:

                Form1 form1 = new Form1();
                form1.DoThis();
                form1.Show();

                J 1 Reply Last reply
                0
                • L Lost User

                  To call a function on Form1, you need a reference to the form in your loginform. It depends on where you instantiate Form1 in your app. Assuming that you instantiate Form1 in loginform (since loginform should ideally be the first form that is loaded in your app from main() method), the code could be something like this:

                  Form1 form1 = new Form1();
                  form1.DoThis();
                  form1.Show();

                  J Offline
                  J Offline
                  jeshra279
                  wrote on last edited by
                  #12

                  my Form1 is the first form which get loaded. loginform is loaded on the click of a button on Form1. Pls tell me how to do this.

                  L 1 Reply Last reply
                  0
                  • J jeshra279

                    my Form1 is the first form which get loaded. loginform is loaded on the click of a button on Form1. Pls tell me how to do this.

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

                    loginform.cs

                    //Reference to Form1
                    Form1 _form1;

                    //Constructor
                    public loginform(Form1 form1) {
                    _form1 = form1;
                    }

                    //Use Form1 referemce
                    public DoSomething() {
                    _form1.DoThat()
                    }

                    Form1.cs

                    private button1_Click(...) {
                    loginform fLogin = new loginform(this);
                    loginform.ShowDialog();
                    }

                    1 Reply Last reply
                    0
                    • T The Man from U N C L E

                      Do you have a reference to form1 in form2? If you do then just call the Functioname method directly. If not then change your structure to have a reference. If the forms are intrinsically linked like this then there is no point doing this with events.

                      If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                      J Offline
                      J Offline
                      jeshra279
                      wrote on last edited by
                      #14

                      Please see my requirement below carefully: need immediate help. I have 2 forms, main Form1 and a loginform. When I start the application, first "Form1" is loaded and then with a button click, user can load "loginform" if required to enable/disable some features/controls on Form1. The sequence is like this: 1) Load main form Form1 2) click a button on Form1 3) Load the loginform. 4) enter user/pwd and click OK button 5) enable/disable "GroupBox" control on Form1 if login sucessful. For this, I made a click event for OK button in loginform, so once user clicks the OK button, I want to call one function which is defined in Form1 as a Public, which enables/disables the "GroupBox" control on Form1. The code structure is like this: in main Form1, i created a function like this: Class Form1() Public Function DoThis() ' Function to enable/disable GroupBox control ....some task... End Function End now in loginform, in the click event for OK button: Class loginform() Click_OK() { DoThis().... 'call function DoThis() of Form1 } End I am not able to call the DoThis() function in loginform. Please suggest me with a piece of code how to do this?? Please remember that Form1 is my main form which is loading first. If anyother way is there to make a password protected feature for GroupBox control in Form1, it will be highly appriciated. Hope my problem is clear..Thanks.

                      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