I have a .NET application that seems to have a really strange bug. The following code represents a form that adds a control (in this case, a label) to a form every few seconds. The code is similar to the application I'm working on. As my application receives data, it will add or remove user controls which represents the data on the fly
When I create the control I set its tool tip. When the control is added to the form, the form takes focus on the screen. This is a really annoying feature as I don't want the user to work with another application and have my application pop up in the foreground every time my application receives new data. The really strange part is that this behavior goes away when I remove the code to set the control's tool tip. Does anyone have any ideas why this is happening
using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.Data
namespace WindowsApplication
/// <summary
/// Summary description for Form1
/// </summary
public class Form1 : System.Windows.Forms.For
private Timer timer
private int yOffset = 0
private int i = 1
private System.Windows.Forms.ToolTip toolTip1
private System.ComponentModel.IContainer components
/// <summary
/// Constructo
/// </summary
public Form1(
InitializeComponent()
StartTimer()
/// <summary
/// Clean up any resources being used
/// </summary
protected override void Dispose( bool disposing
if( disposing
if (components != null)
components.Dispose()
base.Dispose( disposing )
#region Windows Form Designer generated cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
this.components = new System.ComponentModel.Container()
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components)
//
// Form
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13)
this.ClientSize = new System.Drawing.Size(292, 273)
this.Name = "Form1"
this.Text = "Form1"
#endregio
/// <summary
/// Start the timer to dynamically add components
/// </summary
private void StartTimer(
timer = new Timer()
timer.Interval = 5000
timer.Tick += new EventHandler(OnTick)
timer.Start()
/// <summary
/// Called each time the timer's interval has passed
/// </summary
/// <param name="sender"></param
/// <param name="args"></param
private void OnTick(object sender, EventArgs args
SuspendLayout()
Label label = new Label()
label.Text = "Label" + i
label.Size = new Size(200, 15)
label.Location = new Point(0, yOffset)
Controls.Add(label)
toolTip1.SetToolTip(label, "Label" + i)
ResumeLayout()
yOffset += label.Height
i++
/// <summary
/// The main entry point for the application
/// </summary
[STAThread
static void Main()
Application.Run(new Form1())
}