Click here to Skip to main content
12,695,049 members (31,245 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked

Window force forward

, 8 Jun 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A small example of how a program window can be brought up when the user input may need it.

Sample Image - ForceForward.jpg


After all those times that I have used code examples and code snippets from The Code Project, it is time to contribute something back. This article shows how easy it is to use two pre-programmed properties in the Form class in your own project. It shows how easily the this.WindowState and this.TopMost can be used.

The Code

The force forward function is small and simple, it is called with a bool value that forces the window to be on top, or resets it back to normal. If the window has been minimized to the taskbar, the window state is changed to normal so it will pop up from the taskbar.

private void ForceForward(bool forceForward)
    if (forceForward)
        // Force the window up from taskbar if needed...
        if (this.WindowState == FormWindowState.Minimized)
            this.WindowState = FormWindowState.Normal;

        // Top most windows...
        this.TopMost = true;

    // If not force forward, set TopMost back
    // to original state...
        this.TopMost = false;

The Sequence

This program uses a timer to demonstrate. The delay is set to five seconds as the timer is started. For each time the timer “ticks”, the delay decreases by one. When the delay has reached down to zero (or somehow below), it executes ForceForward(true) and then ends the sequence.

private void btStart_Click(object sender, EventArgs e)
    // Start button set to false!
    btStart.Enabled = false;

    // Run once every second (1000ms = 1sec)...
    timer.Enabled = true;
    timer.Interval = 1000;

    // Delay is set to 5 seconds...
    delay = 5;

    // Show on form in begining of countdown...
    lbCountdown.Text = delay.ToString();
    this.Text = delay.ToString();

    // Start the timer...

private void timer_Tick(object sender, EventArgs e)
    // Decrease delay...

    // Show countdown status...
    lbCountdown.Text = delay.ToString();
    this.Text = delay.ToString();

    // When delay has reached zero, ForceForward...
    if (delay <= 0)

private void EndSequence()
    // Stop and disable...
    timer.Enabled = false;

    // Reset countdown label...
    lbCountdown.Text = "";
    this.Text = "Force Forward";

    // Start button now enabled for next force...
    btStart.Enabled = true;

    // Now set back to normal... 

When the end sequence has been executed, the timer is stopped and the program turns back to normal; it does not “top most” windows any more.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Steini kallinn
Software Developer
Iceland Iceland
It all started with enthusiasm for creating mods for Quake 2 many many years ago. After graduation from the technical college, I moved to Denmark and got a Bs. degree in software engineering from Aalborg University.

You may also be interested in...


Comments and Discussions

GeneralNot always on top Pin
--Simas--3-Apr-07 22:18
member--Simas--3-Apr-07 22:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 9 Jun 2006
Article Copyright 2006 by Steini kallinn
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid