Bring application to foreground

Hello everybody!

I used google, I used the search-function in this forums but I can't get an answere. To the risk this has been answered several times before, here is my question:

How do I bring an application to the foreground after it has been minimized with the x-button I am using .NET 1.0 framework (no, there is no chance to update...) on an windows 5.0 pocket pc.

My app registers for an event. When the event is triggered the app should come to front so that the user can see, whats happening. Everything is fine, the app does what it should, but it is not showing up in the foreground. So the problem is not the event-handling.

I tried:
this.Focus()
this.BringToFront()
WindowState = FormWindowState.Normal

Attached is an example application that should show my problem. Try runnig it and than backgrounding it using the x-button. After 100ms it should come to front again!

thx for any help.
M. Abraham

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace DeviceApplication2
{
public class Form1 : System.Windows.Forms.Form
{
private Timer timer1;
private MenuItem menuItem1;
private Label label1;
private int _tick;
private int timeToFront = 100;
private TextBox textBox1;
private System.Windows.Forms.MainMenu mainMenu1;

public Form1()
{
_tick = timeToFront;
InitializeComponent();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}

private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.timer1 = new System.Windows.Forms.Timer();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.mainMenu1.MenuItems.Add(this.menuItem1);
this.menuItem1.Text = "Exit";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
this.label1.Location = new System.Drawing.Point(70, 84);
this.label1.Size = new System.Drawing.Size(100, 20);
this.label1.Text = "Test";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
this.textBox1.Location = new System.Drawing.Point(70, 107);
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.ClientSize = new System.Drawing.Size(240, 188);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}

static void Main()
{
Application.Run(new Form1());
}

private void timer1_Tick(object sender, EventArgs e)
{
_tick--;
textBox1.Text = _tick.ToString();
if (_tick < 1)
{
// here the form should go back to front
this.BringToFront();
//
_tick = timeToFront;
}
}

private void menuItem1_Click(object sender, EventArgs e)
{
Close();
}
}
}


Answer this question

Bring application to foreground