5

I have been working on a windows form application based in c# and I am in need of some assistance. I am trying to recreate the window flicker that most windows applications have when a form loses focus to a parent form. Best way I can explain this is open up calculator open the help window and try to click the calculator, the help window then without falling behind the calculator flickers losing and gaining the shadowing around the edges.

I have managed to regain the focus on the child window when the parent is clicked but this creates a odd flickering effect as the parent window is momentarily brought in front of the child window. I am only guessing but that effect I am looking for appears to be that the calculator is never brought in front of the help window and then the help window is simply activated and deactivated a few times.

I tried doing some searches and I have seen a few topics relating to this but none of the solutions quite match. I am fairly new to making windows form applications so there are still a things I don't understand so be patient with me if I don't understand something at first.

Thank you in advance

An elaboration on the calculator example:

1) open up calculator from windows accessories 2) in the toolbar go to the help tab and open the about calculator option 3) click on the calculator window 4) the about calculator window will then flicker while never falling behind the calculator

The only progress I have made towards this is

    private void MainForm_Activated(object sender, EventArgs e)
    {
        if (Open == true)
        {
            //blink active window

            _addForm.Activate(); //makes window active
        }
    }

The open variable is something I use to keep track of if open forms and is made true when I show another form.

Jesse
  • 107
  • 6
  • What solutions have you found? Please post some of your code. – Sam Leach Apr 19 '13 at 14:25
  • 1
    +1, interesting question actually. Jesse, it took me a few reads to realize what you were describing... you might want to consider writing clearer reproduction steps to people know what you're talking about. – tnw Apr 19 '13 at 14:26
  • Nice, good repro steps. You should also include the code for what you've tried. Looks like you're 90% there. – tnw Apr 19 '13 at 14:32
  • Yep, beaten twice in the minute it took to figure out what you were asking :p. In any case, I will corroborate, the About window is a modal dialog, which means it never actually *allows* its parent to reclaim focus from it. The flicker you refer to is letting you know that a modal child dialog is open, and happens automatically, you don't have to do anything special (except make the dialog modal using ShowDialog()). – neminem Apr 19 '13 at 14:39

2 Answers2

7

In your example the About window is called a modal window. A modal window prevents the user from interacting with the parent window until it is closed. Use Form.ShowDialog instead of Form.Show to present a Form to the user as a modal window.

RogerN
  • 3,761
  • 11
  • 18
  • Thank you sooooooo much I can't believe the solution was this simple!!! Sir I cannot thank you enough!!! – Jesse Apr 19 '13 at 14:39
0

Make the child form modal. This means that the child must be closed properly before focus can be transferred back to the parent.

Dan Iveson
  • 926
  • 6
  • 10