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. Block parent form

Block parent form

Scheduled Pinned Locked Moved C#
helpquestioncareer
9 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.
  • D Offline
    D Offline
    Dominik Reichl
    wrote on last edited by
    #1

    Hello, I've got a main form and a status form. The status form is displayed non-modally (Show method), and updated using Application.DoEvents() while working on a bigger job. Now the problem is that the main form is not blocked while performing the job. Both the status form and the main form can be focused. What I'd like to have is that the main form is blocked and redirects the focus to the status form, just like it would be the case for modal dialogs. Is this possible? I tried setting the Owner property of the status form to the main form, but it didn't have any effect. The ParentForm property is read only, and the Parent property only applies to standard controls, not forms... Thanks and best regards Dominik PS: Moving the job to another thread isn't possible.


    Too many passwords to remember? Try KeePass Password Safe!

    D N X S 4 Replies Last reply
    0
    • D Dominik Reichl

      Hello, I've got a main form and a status form. The status form is displayed non-modally (Show method), and updated using Application.DoEvents() while working on a bigger job. Now the problem is that the main form is not blocked while performing the job. Both the status form and the main form can be focused. What I'd like to have is that the main form is blocked and redirects the focus to the status form, just like it would be the case for modal dialogs. Is this possible? I tried setting the Owner property of the status form to the main form, but it didn't have any effect. The ParentForm property is read only, and the Parent property only applies to standard controls, not forms... Thanks and best regards Dominik PS: Moving the job to another thread isn't possible.


      Too many passwords to remember? Try KeePass Password Safe!

      D Offline
      D Offline
      Dominik Reichl
      wrote on last edited by
      #2

      I've now implemented the following: when the main form runs into the Activated event, I'm calling the Activate method of the status form. This way the main form is somewhat blocked, but there's still the disadvantage that visually the main form still draws the controls as if they could get the focus (for example the main menu items are highlighted when hovering over them). If you know a way how to disable/solve this, please let me know. Thanks and best regards Dominik


      Too many passwords to remember? Try KeePass Password Safe!

      1 Reply Last reply
      0
      • D Dominik Reichl

        Hello, I've got a main form and a status form. The status form is displayed non-modally (Show method), and updated using Application.DoEvents() while working on a bigger job. Now the problem is that the main form is not blocked while performing the job. Both the status form and the main form can be focused. What I'd like to have is that the main form is blocked and redirects the focus to the status form, just like it would be the case for modal dialogs. Is this possible? I tried setting the Owner property of the status form to the main form, but it didn't have any effect. The ParentForm property is read only, and the Parent property only applies to standard controls, not forms... Thanks and best regards Dominik PS: Moving the job to another thread isn't possible.


        Too many passwords to remember? Try KeePass Password Safe!

        N Offline
        N Offline
        Natural_Demon
        wrote on last edited by
        #3

        can't you try to add a this.Click event to the form and captures the user's click and bring the focus the other form?

        Bad = knowing 2 much

        D 1 Reply Last reply
        0
        • N Natural_Demon

          can't you try to add a this.Click event to the form and captures the user's click and bring the focus the other form?

          Bad = knowing 2 much

          D Offline
          D Offline
          Dominik Reichl
          wrote on last edited by
          #4

          See above :-D Thanks for the reply anyway, best regards Dominik


          Too many passwords to remember? Try KeePass Password Safe!

          N 1 Reply Last reply
          0
          • D Dominik Reichl

            See above :-D Thanks for the reply anyway, best regards Dominik


            Too many passwords to remember? Try KeePass Password Safe!

            N Offline
            N Offline
            Natural_Demon
            wrote on last edited by
            #5

            you can also use panels in the mainform, switch to a panel with the text 'please wait' and switch back after your other jobs finish.

            Bad = knowing 2 much

            1 Reply Last reply
            0
            • D Dominik Reichl

              Hello, I've got a main form and a status form. The status form is displayed non-modally (Show method), and updated using Application.DoEvents() while working on a bigger job. Now the problem is that the main form is not blocked while performing the job. Both the status form and the main form can be focused. What I'd like to have is that the main form is blocked and redirects the focus to the status form, just like it would be the case for modal dialogs. Is this possible? I tried setting the Owner property of the status form to the main form, but it didn't have any effect. The ParentForm property is read only, and the Parent property only applies to standard controls, not forms... Thanks and best regards Dominik PS: Moving the job to another thread isn't possible.


              Too many passwords to remember? Try KeePass Password Safe!

              X Offline
              X Offline
              Xmen Real
              wrote on last edited by
              #6

              this.Enabled = false;

              will it work ?

              TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

              ----------------------------------------------- 128 bit encrypted signature, crack if you can

              D 1 Reply Last reply
              0
              • X Xmen Real

                this.Enabled = false;

                will it work ?

                TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

                ----------------------------------------------- 128 bit encrypted signature, crack if you can

                D Offline
                D Offline
                Dominik Reichl
                wrote on last edited by
                #7

                Yes, this prevents visual effects on hovering, but also grays out all dialog elements (which is actually good I guess). Thanks and best regards Dominik


                Too many passwords to remember? Try KeePass Password Safe!

                1 Reply Last reply
                0
                • D Dominik Reichl

                  Hello, I've got a main form and a status form. The status form is displayed non-modally (Show method), and updated using Application.DoEvents() while working on a bigger job. Now the problem is that the main form is not blocked while performing the job. Both the status form and the main form can be focused. What I'd like to have is that the main form is blocked and redirects the focus to the status form, just like it would be the case for modal dialogs. Is this possible? I tried setting the Owner property of the status form to the main form, but it didn't have any effect. The ParentForm property is read only, and the Parent property only applies to standard controls, not forms... Thanks and best regards Dominik PS: Moving the job to another thread isn't possible.


                  Too many passwords to remember? Try KeePass Password Safe!

                  S Offline
                  S Offline
                  Saksida Bojan
                  wrote on last edited by
                  #8

                  If you call sub form non-modally, it will run in diffrent thread. Why do you want to use non modally? And if you want to block executing main form and wait till status form is finished, it is easy if you called it modally with ShowDialog() method. And if you insist in non moddaly, make some static variable in status form boolean type, and in the main forum ovverride focused event PS: Moddaly and non moddaly means only that it runs either in diffrent or same thread

                  L 1 Reply Last reply
                  0
                  • S Saksida Bojan

                    If you call sub form non-modally, it will run in diffrent thread. Why do you want to use non modally? And if you want to block executing main form and wait till status form is finished, it is easy if you called it modally with ShowDialog() method. And if you insist in non moddaly, make some static variable in status form boolean type, and in the main forum ovverride focused event PS: Moddaly and non moddaly means only that it runs either in diffrent or same thread

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

                    Saksida Bojan wrote:

                    Moddaly and non moddaly means only that it runs either in diffrent or same thread

                    I don't think so. It means they use different message pumps, however all message pumps are executed (one at a time) by one and only one thread. Here is an experiment to prove it: - create main form Form1 with a ListBox and a Button; it will be shown modelessly; - create Form2 with a ListBox and a Button; it will be shown modally; - add the following to Form1:

                    public partial class Form1 : Form {
                    	int count;
                    
                    	public Form1() {
                    		InitializeComponent();
                    	}
                    
                    	public void log(string s) {
                    		lb.Items.Add(s);
                    	}
                    
                    	private void button1\_Click(object sender, EventArgs e) {
                    		log("Thread ID="+Thread.CurrentThread.ManagedThreadId);
                    		Form2 f=new Form2();
                    		f.ShowDialog();
                    	}
                    
                    	protected override void WndProc(ref Message m) {
                    		count++;
                    		if (count<5) log("Thread ID="+Thread.CurrentThread.ManagedThreadId);
                    		base.WndProc(ref m);
                    	}
                    }
                    

                    - add basically the same code to Form2 (without new Form2/ShowDialog) - run, click button, see all thread IDs, on second form, click button, see all thread IDs equal to the former ones. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                    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