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. Show Form and Disable Button How?

Show Form and Disable Button How?

Scheduled Pinned Locked Moved C#
questionhelp
8 Posts 4 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.
  • S Offline
    S Offline
    soulidentities
    wrote on last edited by
    #1

    Hi again friends i have 3 diff forms. 1. BaseForm.( Includes 2 button, Buttons Text "Form1" and "Form2") 2. Form1. (Just inherited BaseForm) 3. Form2. (Just inherited BaseForm) I know its easy. I have tried a lot and google a lot but cant find... Anyway I am asking for help here. when I run program the base form will appears.If the Button Form1 clicked then it shows form Form1 and disable Form1 button in that form. and Hide BaseForm. same action for Button Form1. Can anyone show me some code or sample plz. My other question is When I click the Right Top Cross button then the Background BaseForm Still running. I want to close all form If I click the cross. How Can it possible. Plz show mw the way. Thanks Friends. :)

    M D P 3 Replies Last reply
    0
    • S soulidentities

      Hi again friends i have 3 diff forms. 1. BaseForm.( Includes 2 button, Buttons Text "Form1" and "Form2") 2. Form1. (Just inherited BaseForm) 3. Form2. (Just inherited BaseForm) I know its easy. I have tried a lot and google a lot but cant find... Anyway I am asking for help here. when I run program the base form will appears.If the Button Form1 clicked then it shows form Form1 and disable Form1 button in that form. and Hide BaseForm. same action for Button Form1. Can anyone show me some code or sample plz. My other question is When I click the Right Top Cross button then the Background BaseForm Still running. I want to close all form If I click the cross. How Can it possible. Plz show mw the way. Thanks Friends. :)

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      ok when you click button for form 1 or 2, hide the base form then show the desired form with the ShowDialog() method. after which you then show the baseForm again Then for the disabled buttons you simply close the current form.

      soulidentities wrote:

      I want to close all form If I click the cross

      Handle the on close event for each form, then call Application.Exit();

      If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting

      S 1 Reply Last reply
      0
      • M musefan

        ok when you click button for form 1 or 2, hide the base form then show the desired form with the ShowDialog() method. after which you then show the baseForm again Then for the disabled buttons you simply close the current form.

        soulidentities wrote:

        I want to close all form If I click the cross

        Handle the on close event for each form, then call Application.Exit();

        If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting

        S Offline
        S Offline
        soulidentities
        wrote on last edited by
        #3

        Thanks friend for fast reply. I take the method ShowDialog() from your advice but I cant take the "Simply Close the Current Form" I need to disable the button. Its my real problem. I mean when i click the button Form1, it will show Form1 form and hide base form(in the background baseform load newly as well because its being Inherited). I tried to set click Event on the button in the BaseForm so that when it click it will show form and disable button. But since the BaseForm load freashly it cant not detect the click and the button visible. Plz some one help me. Thanks :)

        M 1 Reply Last reply
        0
        • S soulidentities

          Thanks friend for fast reply. I take the method ShowDialog() from your advice but I cant take the "Simply Close the Current Form" I need to disable the button. Its my real problem. I mean when i click the button Form1, it will show Form1 form and hide base form(in the background baseform load newly as well because its being Inherited). I tried to set click Event on the button in the BaseForm so that when it click it will show form and disable button. But since the BaseForm load freashly it cant not detect the click and the button visible. Plz some one help me. Thanks :)

          M Offline
          M Offline
          musefan
          wrote on last edited by
          #4

          ok you lost me now :) let me get this straight - BaseForm has 2 buttons called 'Form1' and 'Form2' only Form1 has 1 button called 'disable' Form2 has 1 button called 'disable' Now... when you click 'Form1' you want to hide baseForm and show Form1, right? then when you click 'Disable' on Form1 you want to hide Form1 and then re-show BaseForm, right? Same for Form2, right?

          If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting

          S 1 Reply Last reply
          0
          • S soulidentities

            Hi again friends i have 3 diff forms. 1. BaseForm.( Includes 2 button, Buttons Text "Form1" and "Form2") 2. Form1. (Just inherited BaseForm) 3. Form2. (Just inherited BaseForm) I know its easy. I have tried a lot and google a lot but cant find... Anyway I am asking for help here. when I run program the base form will appears.If the Button Form1 clicked then it shows form Form1 and disable Form1 button in that form. and Hide BaseForm. same action for Button Form1. Can anyone show me some code or sample plz. My other question is When I click the Right Top Cross button then the Background BaseForm Still running. I want to close all form If I click the cross. How Can it possible. Plz show mw the way. Thanks Friends. :)

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

            I haven't dealt with an inherited form but I think this achieves what you want - adapt to suit.

            using System;
            using System.Windows.Forms;

            public partial class BaseForm : Form
            {
            public BaseForm()
            {
            InitializeComponent();
            }
            public BaseForm(bool showForm1Button)
            : this()
            {
            btnForm1.Visible = showForm1Button;
            }

            private void btnForm1\_Click(object sender, EventArgs e)
            {
                BaseForm newBaseForm = new BaseForm(false);
                newBaseForm.FormClosing += new FormClosingEventHandler(newBaseForm\_FormClosing);
                newBaseForm.Show();
                Hide();
            }
            
            void newBaseForm\_FormClosing(object sender, FormClosingEventArgs e)
            {
                Close();
            }
            

            }

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

            1 Reply Last reply
            0
            • M musefan

              ok you lost me now :) let me get this straight - BaseForm has 2 buttons called 'Form1' and 'Form2' only Form1 has 1 button called 'disable' Form2 has 1 button called 'disable' Now... when you click 'Form1' you want to hide baseForm and show Form1, right? then when you click 'Disable' on Form1 you want to hide Form1 and then re-show BaseForm, right? Same for Form2, right?

              If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting

              S Offline
              S Offline
              soulidentities
              wrote on last edited by
              #6

              :) Im sorry i made u confused You are almost clear with my probs just a lil misunderstood. Im gonna clear it now. Form1 has 1 button called 'btnForm1' and text 'Form1' Form2 has 1 button called 'btnForm2' and text 'Form2' now when I click 'Form1' I want to hide base form and show Form1 and Disable the btnForm1 button. Means u cant click btnForm1. U just can click Form2 button when form1 shows. I think now I made u clear. Thanks buddy :)

              1 Reply Last reply
              0
              • S soulidentities

                Hi again friends i have 3 diff forms. 1. BaseForm.( Includes 2 button, Buttons Text "Form1" and "Form2") 2. Form1. (Just inherited BaseForm) 3. Form2. (Just inherited BaseForm) I know its easy. I have tried a lot and google a lot but cant find... Anyway I am asking for help here. when I run program the base form will appears.If the Button Form1 clicked then it shows form Form1 and disable Form1 button in that form. and Hide BaseForm. same action for Button Form1. Can anyone show me some code or sample plz. My other question is When I click the Right Top Cross button then the Background BaseForm Still running. I want to close all form If I click the cross. How Can it possible. Plz show mw the way. Thanks Friends. :)

                P Offline
                P Offline
                Paul Kettley
                wrote on last edited by
                #7

                Hi SoulIdentities, I would use an Event Handler, that contains your own bespoke EventArgs. You can contain within that EventArgs a delegate that points to a function. Your base class will contain the function and you will register the event handler of your childs form to your base form. When you close the child form, you will call the eventhandler, which will in turn post up to the base form which will react with a close of itself. Cheers, Paul

                S 1 Reply Last reply
                0
                • P Paul Kettley

                  Hi SoulIdentities, I would use an Event Handler, that contains your own bespoke EventArgs. You can contain within that EventArgs a delegate that points to a function. Your base class will contain the function and you will register the event handler of your childs form to your base form. When you close the child form, you will call the eventhandler, which will in turn post up to the base form which will react with a close of itself. Cheers, Paul

                  S Offline
                  S Offline
                  soulidentities
                  wrote on last edited by
                  #8

                  Sorry Paul I am not clear. Can you make some example. I will appritiate it. 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