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. Is it possible to enable controls on the form from a class.

Is it possible to enable controls on the form from a class.

Scheduled Pinned Locked Moved C#
csharp
11 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.
  • J Offline
    J Offline
    Janu_M
    wrote on last edited by
    #1

    Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu

    L D M J 4 Replies Last reply
    0
    • J Janu_M

      Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu

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

      Ramu.M wrote:

      Is it possible to enable controls on the form from a class

      yes

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      J 1 Reply Last reply
      0
      • L Luc Pattyn

        Ramu.M wrote:

        Is it possible to enable controls on the form from a class

        yes

        Luc Pattyn


        try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


        J Offline
        J Offline
        Janu_M
        wrote on last edited by
        #3

        plz tell me how to do it? (Any guidelines of code) Thanks for your reply

        C L 2 Replies Last reply
        0
        • J Janu_M

          Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu

          D Offline
          D Offline
          Developer611
          wrote on last edited by
          #4

          Hi . Yes you can , something like following code : public class ControlForm { public static void EnableTextBox() { FrmTest frmTest = new frmTest(); frmTest.txtName.Enable = true; } } Important :Set your control modifier property to Internal or Public Bad Programming :Don't try to do this . It's not a smart coding .

          DMASTER

          1 Reply Last reply
          0
          • J Janu_M

            plz tell me how to do it? (Any guidelines of code) Thanks for your reply

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            The other class must know about the form - so you must pass details of the form to the other class (remember, forms are classes too) somehow. Then the class can access the form. You must provide a mechanism on the form to receive the request

            class MyForm : Form
            {
            ...

            // The form class needs a mechanism to receive the request to
            // disable the controls.
            public void DisableControls()
            {
                // Code to disable the controls goes here
            }
            

            }

            class MyOtherClass
            {
            // The other class needs to store the form
            private MyForm myForm;

            // In this example the other class gets told about the form at
            // the time it is instantiated. It could also set up a property
            // to receive that information.
            public MyOtherClass(MyForm myForm)
            {
                this.myForm = myForm;
            }
            
            // The class has some code somewhere that needs to disable the
            // controls on the form.
            public SomeMethodThatNeedsToDisableTheControls()
            {
                ...
                myForm.DisableControls();
                ...
            }
            

            }

            Does this help?


            Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

            1 Reply Last reply
            0
            • J Janu_M

              Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu

              M Offline
              M Offline
              Manoj Kumar Rai
              wrote on last edited by
              #6

              Even you can use Delegates for Enabling/Disabling controls of the Form. The Delegate will remove the requirement to declare control objects (Text etc) public.

              Manoj Never Gives up

              C 1 Reply Last reply
              0
              • J Janu_M

                plz tell me how to do it? (Any guidelines of code) Thanks for your reply

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

                If you hold a reference to the form, you can manipulate everything on it that is declared public, as in myForm.myButton.Enabled=true; But it is considered bad design to make controls public, since everyone holding the reference (myForm) can also replace, resize, move, hide, ... said control. In fact, it is almost always wrong to provide public fields, only methods and properties should be candidates for the public attribute. An acceptable approach is: - keep the controls private (or protected) to your form class; - provide public methods (or properties) inside your form class, that offer the required functionality to the outside world, no more, no less; - pass the form's reference to your class and have it use the public methods or properties. And if you are familiar with delegates, they offer the best approach. It basically means your form creates a delegate (that's like a function pointer connected to the form's object), so now it can pass that delegate to your class, without even having to pass the form's reference itself. That is encapsulation, provide as little as possible, just give what is absolutely necessary. :)

                Luc Pattyn


                try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                1 Reply Last reply
                0
                • M Manoj Kumar Rai

                  Even you can use Delegates for Enabling/Disabling controls of the Form. The Delegate will remove the requirement to declare control objects (Text etc) public.

                  Manoj Never Gives up

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #8

                  Manoj Kumar Rai wrote:

                  The Delegate will remove the requirement to declare control objects (Text etc) public.

                  Text is a parameter on the control. You cannot make that public. You must make the control public, or create a new property on the form that proxies for the control's property.


                  Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

                  M 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    Manoj Kumar Rai wrote:

                    The Delegate will remove the requirement to declare control objects (Text etc) public.

                    Text is a parameter on the control. You cannot make that public. You must make the control public, or create a new property on the form that proxies for the control's property.


                    Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

                    M Offline
                    M Offline
                    Manoj Kumar Rai
                    wrote on last edited by
                    #9

                    Yes Yes, You are corrrect. I meant TextBox there.

                    Manoj Never Gives up

                    1 Reply Last reply
                    0
                    • J Janu_M

                      Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu

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

                      Thank you very much. Ramu

                      D 1 Reply Last reply
                      0
                      • J Janu_M

                        Thank you very much. Ramu

                        D Offline
                        D Offline
                        Developer611
                        wrote on last edited by
                        #11

                        I'm already say it . So , what ...:confused:

                        DMASTER

                        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