How does the Form.Modal property changes when using button in a form?How do you give a C# Auto-Property a default value?How to prevent buttons from submitting formsPassing data between two forms with propertiespassing data between two forms using propertiesAccessing string from another FormHow to create Form On Top and cannot access other formsCan't pass a Windows Form to another via constructorHide and restore the GUI Mutiple forms in c#How do I make a button in one form to do actions in another formIn C# how to open third form inside first form when i click a button of the second form

Is the U.S. Code copyrighted by the Government?

lightning-datatable row number error

Are paving bricks differently sized for sand bedding vs mortar bedding?

2.8 Why are collections grayed out? How can I open them?

copy and scale one figure (wheel)

Is it better practice to read straight from sheet music rather than memorize it?

Pre-mixing cryogenic fuels and using only one fuel tank

What does chmod -u do?

What does routing an IP address mean?

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Did arcade monitors have same pixel aspect ratio as TV sets?

Is it possible to have a strip of cold climate in the middle of a planet?

How do I color the graph in datavisualization?

Why Shazam when there is already Superman?

Biological Blimps: Propulsion

L1 and Ln cache: when are they written?

Melting point of aspirin, contradicting sources

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Symbol used to indicate indivisibility

Why can Carol Danvers change her suit colours in the first place?

Is there any references on the tensor product of presentable (1-)categories?

What should you do if you miss a job interview (deliberately)?

Which one is correct as adjective “protruding” or “protruded”?

Yosemite Fire Rings - What to Expect?



How does the Form.Modal property changes when using button in a form?


How do you give a C# Auto-Property a default value?How to prevent buttons from submitting formsPassing data between two forms with propertiespassing data between two forms using propertiesAccessing string from another FormHow to create Form On Top and cannot access other formsCan't pass a Windows Form to another via constructorHide and restore the GUI Mutiple forms in c#How do I make a button in one form to do actions in another formIn C# how to open third form inside first form when i click a button of the second form













-1















I'm using 2 forms in an application in which, clicking button in form1 opens form2. While opening form2, the Modal property of form2 is FALSE. But, once on clicking the button in form2, the value of this property is set to TRUE. I have used the below code in the application.



Form1



private void button1_Click(object sender, EventArgs e)

Form2 f2 = new Form2();
bool isModal = f2.Modal;
f2.ShowDialog();



Form2



private void button1_Click(object sender, EventArgs e)

bool isModal = this.Modal;



Kindly share your ideas on how this is updated?



Thanks,



Sindhu










share|improve this question






















  • stackoverflow.com/help/someone-answers

    – mjwills
    9 hours ago















-1















I'm using 2 forms in an application in which, clicking button in form1 opens form2. While opening form2, the Modal property of form2 is FALSE. But, once on clicking the button in form2, the value of this property is set to TRUE. I have used the below code in the application.



Form1



private void button1_Click(object sender, EventArgs e)

Form2 f2 = new Form2();
bool isModal = f2.Modal;
f2.ShowDialog();



Form2



private void button1_Click(object sender, EventArgs e)

bool isModal = this.Modal;



Kindly share your ideas on how this is updated?



Thanks,



Sindhu










share|improve this question






















  • stackoverflow.com/help/someone-answers

    – mjwills
    9 hours ago













-1












-1








-1


0






I'm using 2 forms in an application in which, clicking button in form1 opens form2. While opening form2, the Modal property of form2 is FALSE. But, once on clicking the button in form2, the value of this property is set to TRUE. I have used the below code in the application.



Form1



private void button1_Click(object sender, EventArgs e)

Form2 f2 = new Form2();
bool isModal = f2.Modal;
f2.ShowDialog();



Form2



private void button1_Click(object sender, EventArgs e)

bool isModal = this.Modal;



Kindly share your ideas on how this is updated?



Thanks,



Sindhu










share|improve this question














I'm using 2 forms in an application in which, clicking button in form1 opens form2. While opening form2, the Modal property of form2 is FALSE. But, once on clicking the button in form2, the value of this property is set to TRUE. I have used the below code in the application.



Form1



private void button1_Click(object sender, EventArgs e)

Form2 f2 = new Form2();
bool isModal = f2.Modal;
f2.ShowDialog();



Form2



private void button1_Click(object sender, EventArgs e)

bool isModal = this.Modal;



Kindly share your ideas on how this is updated?



Thanks,



Sindhu







c# forms winforms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Sindhu TNSindhu TN

95




95












  • stackoverflow.com/help/someone-answers

    – mjwills
    9 hours ago

















  • stackoverflow.com/help/someone-answers

    – mjwills
    9 hours ago
















stackoverflow.com/help/someone-answers

– mjwills
9 hours ago





stackoverflow.com/help/someone-answers

– mjwills
9 hours ago












3 Answers
3






active

oldest

votes


















2














The docs state:




Gets a value indicating whether this form is displayed modally.




The key word here is is.



Let's look at your code:



Form2 f2 = new Form2();
bool isModal = f2.Modal;
f2.ShowDialog();


The question you need to ask is "in that second line, is the form at that time shown modally?"



The answer is clearly No, since it is only shown modally on the third line. If you think logically, this makes perfect sense. The form doesn't know whether you are going to call Show or ShowDialog - so Modal can't tell you about the future - it can only tell you about the current state of affairs.



Thus, on the second line, Modal must (according to the docs) return false.



OK, so why is it true in here?



private void button1_Click(object sender, EventArgs e)

bool isModal = this.Modal;



Well, based on the docs we need to ask ourselves whether this is currently displayed modally when the button is clicked. Yes at that time it is, so it must (according to the docs) return true.






share|improve this answer
































    0














    While it may appear to have something to do with the buttons, it does not. It has to do with ShowDialog(); method.



    If you check before f2.ShowDialog();, the Modal will be false. Check after and it will be true.



    This f2.ShowDialog(); is what sets the property to true.



    You may use f2.Show() and it will stay false in this case for obvious reason.






    share|improve this answer
































      0














      As @CodingYoshi said, the method that is setting the Form.Modal to true is Form.ShowDialog(). This is why f2.Modal is false, because it is called before f2.ShowDialog().

      The problem is checking the f2.Modal after calling f2.ShowDialog. The problem is that you cannot execute any further code lines in the code block after calling f2.ShowDialog(). Thus, there is no way to call f2.Modal.

      The best way to see this difference to check Modal first in your constructor and then check it again in the Form.Load event. The constructor is called before ShowDialog is called, but Form.Load and Button.clicked are called after ShowDialog is called. Thus, you have different values for the Modal property.

      Here the constructor of Form2:



      Sub New ()
      ' This call is required by the designer.
      InitializeComponent()

      Console.WriteLine(Me.Modal) ' is always false
      End Sub


      And then Form.Loading event of Form2:



      Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      Console.WriteLine(Me.Modal) ' will return true if object is called via ShowDialog()
      End Sub





      share|improve this answer






















        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55279937%2fhow-does-the-form-modal-property-changes-when-using-button-in-a-form%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        The docs state:




        Gets a value indicating whether this form is displayed modally.




        The key word here is is.



        Let's look at your code:



        Form2 f2 = new Form2();
        bool isModal = f2.Modal;
        f2.ShowDialog();


        The question you need to ask is "in that second line, is the form at that time shown modally?"



        The answer is clearly No, since it is only shown modally on the third line. If you think logically, this makes perfect sense. The form doesn't know whether you are going to call Show or ShowDialog - so Modal can't tell you about the future - it can only tell you about the current state of affairs.



        Thus, on the second line, Modal must (according to the docs) return false.



        OK, so why is it true in here?



        private void button1_Click(object sender, EventArgs e)

        bool isModal = this.Modal;



        Well, based on the docs we need to ask ourselves whether this is currently displayed modally when the button is clicked. Yes at that time it is, so it must (according to the docs) return true.






        share|improve this answer





























          2














          The docs state:




          Gets a value indicating whether this form is displayed modally.




          The key word here is is.



          Let's look at your code:



          Form2 f2 = new Form2();
          bool isModal = f2.Modal;
          f2.ShowDialog();


          The question you need to ask is "in that second line, is the form at that time shown modally?"



          The answer is clearly No, since it is only shown modally on the third line. If you think logically, this makes perfect sense. The form doesn't know whether you are going to call Show or ShowDialog - so Modal can't tell you about the future - it can only tell you about the current state of affairs.



          Thus, on the second line, Modal must (according to the docs) return false.



          OK, so why is it true in here?



          private void button1_Click(object sender, EventArgs e)

          bool isModal = this.Modal;



          Well, based on the docs we need to ask ourselves whether this is currently displayed modally when the button is clicked. Yes at that time it is, so it must (according to the docs) return true.






          share|improve this answer



























            2












            2








            2







            The docs state:




            Gets a value indicating whether this form is displayed modally.




            The key word here is is.



            Let's look at your code:



            Form2 f2 = new Form2();
            bool isModal = f2.Modal;
            f2.ShowDialog();


            The question you need to ask is "in that second line, is the form at that time shown modally?"



            The answer is clearly No, since it is only shown modally on the third line. If you think logically, this makes perfect sense. The form doesn't know whether you are going to call Show or ShowDialog - so Modal can't tell you about the future - it can only tell you about the current state of affairs.



            Thus, on the second line, Modal must (according to the docs) return false.



            OK, so why is it true in here?



            private void button1_Click(object sender, EventArgs e)

            bool isModal = this.Modal;



            Well, based on the docs we need to ask ourselves whether this is currently displayed modally when the button is clicked. Yes at that time it is, so it must (according to the docs) return true.






            share|improve this answer















            The docs state:




            Gets a value indicating whether this form is displayed modally.




            The key word here is is.



            Let's look at your code:



            Form2 f2 = new Form2();
            bool isModal = f2.Modal;
            f2.ShowDialog();


            The question you need to ask is "in that second line, is the form at that time shown modally?"



            The answer is clearly No, since it is only shown modally on the third line. If you think logically, this makes perfect sense. The form doesn't know whether you are going to call Show or ShowDialog - so Modal can't tell you about the future - it can only tell you about the current state of affairs.



            Thus, on the second line, Modal must (according to the docs) return false.



            OK, so why is it true in here?



            private void button1_Click(object sender, EventArgs e)

            bool isModal = this.Modal;



            Well, based on the docs we need to ask ourselves whether this is currently displayed modally when the button is clicked. Yes at that time it is, so it must (according to the docs) return true.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered 2 days ago









            mjwillsmjwills

            15.7k42643




            15.7k42643























                0














                While it may appear to have something to do with the buttons, it does not. It has to do with ShowDialog(); method.



                If you check before f2.ShowDialog();, the Modal will be false. Check after and it will be true.



                This f2.ShowDialog(); is what sets the property to true.



                You may use f2.Show() and it will stay false in this case for obvious reason.






                share|improve this answer





























                  0














                  While it may appear to have something to do with the buttons, it does not. It has to do with ShowDialog(); method.



                  If you check before f2.ShowDialog();, the Modal will be false. Check after and it will be true.



                  This f2.ShowDialog(); is what sets the property to true.



                  You may use f2.Show() and it will stay false in this case for obvious reason.






                  share|improve this answer



























                    0












                    0








                    0







                    While it may appear to have something to do with the buttons, it does not. It has to do with ShowDialog(); method.



                    If you check before f2.ShowDialog();, the Modal will be false. Check after and it will be true.



                    This f2.ShowDialog(); is what sets the property to true.



                    You may use f2.Show() and it will stay false in this case for obvious reason.






                    share|improve this answer















                    While it may appear to have something to do with the buttons, it does not. It has to do with ShowDialog(); method.



                    If you check before f2.ShowDialog();, the Modal will be false. Check after and it will be true.



                    This f2.ShowDialog(); is what sets the property to true.



                    You may use f2.Show() and it will stay false in this case for obvious reason.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 days ago

























                    answered 2 days ago









                    CodingYoshiCodingYoshi

                    17.6k22436




                    17.6k22436





















                        0














                        As @CodingYoshi said, the method that is setting the Form.Modal to true is Form.ShowDialog(). This is why f2.Modal is false, because it is called before f2.ShowDialog().

                        The problem is checking the f2.Modal after calling f2.ShowDialog. The problem is that you cannot execute any further code lines in the code block after calling f2.ShowDialog(). Thus, there is no way to call f2.Modal.

                        The best way to see this difference to check Modal first in your constructor and then check it again in the Form.Load event. The constructor is called before ShowDialog is called, but Form.Load and Button.clicked are called after ShowDialog is called. Thus, you have different values for the Modal property.

                        Here the constructor of Form2:



                        Sub New ()
                        ' This call is required by the designer.
                        InitializeComponent()

                        Console.WriteLine(Me.Modal) ' is always false
                        End Sub


                        And then Form.Loading event of Form2:



                        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                        Console.WriteLine(Me.Modal) ' will return true if object is called via ShowDialog()
                        End Sub





                        share|improve this answer



























                          0














                          As @CodingYoshi said, the method that is setting the Form.Modal to true is Form.ShowDialog(). This is why f2.Modal is false, because it is called before f2.ShowDialog().

                          The problem is checking the f2.Modal after calling f2.ShowDialog. The problem is that you cannot execute any further code lines in the code block after calling f2.ShowDialog(). Thus, there is no way to call f2.Modal.

                          The best way to see this difference to check Modal first in your constructor and then check it again in the Form.Load event. The constructor is called before ShowDialog is called, but Form.Load and Button.clicked are called after ShowDialog is called. Thus, you have different values for the Modal property.

                          Here the constructor of Form2:



                          Sub New ()
                          ' This call is required by the designer.
                          InitializeComponent()

                          Console.WriteLine(Me.Modal) ' is always false
                          End Sub


                          And then Form.Loading event of Form2:



                          Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                          Console.WriteLine(Me.Modal) ' will return true if object is called via ShowDialog()
                          End Sub





                          share|improve this answer

























                            0












                            0








                            0







                            As @CodingYoshi said, the method that is setting the Form.Modal to true is Form.ShowDialog(). This is why f2.Modal is false, because it is called before f2.ShowDialog().

                            The problem is checking the f2.Modal after calling f2.ShowDialog. The problem is that you cannot execute any further code lines in the code block after calling f2.ShowDialog(). Thus, there is no way to call f2.Modal.

                            The best way to see this difference to check Modal first in your constructor and then check it again in the Form.Load event. The constructor is called before ShowDialog is called, but Form.Load and Button.clicked are called after ShowDialog is called. Thus, you have different values for the Modal property.

                            Here the constructor of Form2:



                            Sub New ()
                            ' This call is required by the designer.
                            InitializeComponent()

                            Console.WriteLine(Me.Modal) ' is always false
                            End Sub


                            And then Form.Loading event of Form2:



                            Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                            Console.WriteLine(Me.Modal) ' will return true if object is called via ShowDialog()
                            End Sub





                            share|improve this answer













                            As @CodingYoshi said, the method that is setting the Form.Modal to true is Form.ShowDialog(). This is why f2.Modal is false, because it is called before f2.ShowDialog().

                            The problem is checking the f2.Modal after calling f2.ShowDialog. The problem is that you cannot execute any further code lines in the code block after calling f2.ShowDialog(). Thus, there is no way to call f2.Modal.

                            The best way to see this difference to check Modal first in your constructor and then check it again in the Form.Load event. The constructor is called before ShowDialog is called, but Form.Load and Button.clicked are called after ShowDialog is called. Thus, you have different values for the Modal property.

                            Here the constructor of Form2:



                            Sub New ()
                            ' This call is required by the designer.
                            InitializeComponent()

                            Console.WriteLine(Me.Modal) ' is always false
                            End Sub


                            And then Form.Loading event of Form2:



                            Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                            Console.WriteLine(Me.Modal) ' will return true if object is called via ShowDialog()
                            End Sub






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 2 days ago









                            Code PopeCode Pope

                            1,30621635




                            1,30621635



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55279937%2fhow-does-the-form-modal-property-changes-when-using-button-in-a-form%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현