J
jeff
I've searched for this problem but haven't found any posts on it - hope this
isn't a duplicate...
I had a strange event occur earlier today and have isolated the 'problem'.
In its simplest form I have a monthCalendar control and textBox control on a
form, and have added an event handler that clears the text in the textBox
when the DateChanged event is fired. The problem is that I find if text is
entered in the textBox, after just under 2 minutes (on my system) the
DateChanged event is apparently fired (even if no activity is occurring) and
the textBox will be cleared.
To isolate this I went back to the DateChanged event handler example in the
MS docs and stripped the code down (also changing some of the values for
sizes and alignments). Here's what I have:
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.TextBox textBox1;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.Location = new System.Drawing.Point(248, 16);
this.textBox1.Multiline = true;
this.textBox1.Size = new System.Drawing.Size(224, 32);
// Create the calendar.
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
// Set the calendar location.
this.monthCalendar1.Location = new System.Drawing.Point(47, 16);
this.monthCalendar1.DateChanged += new
System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateChanged);
// Set up how the form should be displayed and add the controls to
the form.
this.ClientSize = new System.Drawing.Size(500, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[]
{this.textBox1, this.monthCalendar1});
this.Text = "Month Calendar Example";
}
private void monthCalendar1_DateChanged(object sender,
System.Windows.Forms.DateRangeEventArgs e)
{
// If the date changes, clear the text box
this.textBox1.Text = "";
}
}
Is this behaviour documented anywhere?
I assume that I'm merely using the wrong "tool" and should be monitoring a
different event or clearing the textbox differently, but this still seems
very odd to me.
I initially set this up with Visual Studio 2005 Beta 2 but tested the above
in SharpDevelop.
Any insight would be appreciated.
isn't a duplicate...
I had a strange event occur earlier today and have isolated the 'problem'.
In its simplest form I have a monthCalendar control and textBox control on a
form, and have added an event handler that clears the text in the textBox
when the DateChanged event is fired. The problem is that I find if text is
entered in the textBox, after just under 2 minutes (on my system) the
DateChanged event is apparently fired (even if no activity is occurring) and
the textBox will be cleared.
To isolate this I went back to the DateChanged event handler example in the
MS docs and stripped the code down (also changing some of the values for
sizes and alignments). Here's what I have:
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.TextBox textBox1;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.Location = new System.Drawing.Point(248, 16);
this.textBox1.Multiline = true;
this.textBox1.Size = new System.Drawing.Size(224, 32);
// Create the calendar.
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
// Set the calendar location.
this.monthCalendar1.Location = new System.Drawing.Point(47, 16);
this.monthCalendar1.DateChanged += new
System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateChanged);
// Set up how the form should be displayed and add the controls to
the form.
this.ClientSize = new System.Drawing.Size(500, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[]
{this.textBox1, this.monthCalendar1});
this.Text = "Month Calendar Example";
}
private void monthCalendar1_DateChanged(object sender,
System.Windows.Forms.DateRangeEventArgs e)
{
// If the date changes, clear the text box
this.textBox1.Text = "";
}
}
Is this behaviour documented anywhere?
I assume that I'm merely using the wrong "tool" and should be monitoring a
different event or clearing the textbox differently, but this still seems
very odd to me.
I initially set this up with Visual Studio 2005 Beta 2 but tested the above
in SharpDevelop.
Any insight would be appreciated.