hi,
i did some more testing and it appears that the Click event is not raised
when you programatically change the 'Checked' property. (in my original
test i thought it did, but i can't reproduce it now). however the
CheckedChanged event is raised, as expected.
for your case, even if you only use CheckedChanged it is still going to fire
in your FormLoad and pop up the warning. to get around this you can either
choose to add the CheckedChanged eventhandler after all your initialisation
code is done, or you can set a boolean variable called 'Loading' to true and
in the CheckedChanged EventHandler, you have something like:
if(Loading) return;
below is minimal form code to demonstrate how Click is not caused
programatically (in this case at least!). if it is behaving differently for
you maybe you could post your code and we can see if there is an explanation
for the unexpected behaviour.
tim
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web;
namespace Test
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RadioButton radioButton1;
private System.ComponentModel.IContainer components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(72, 96);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Toggle";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(64, 56);
this.radioButton1.Name = "radioButton1";
this.radioButton1.TabIndex = 3;
this.radioButton1.Text = "radioButton1";
this.radioButton1.Click += new
System.EventHandler(this.radioButton1_Click);
this.radioButton1.CheckedChanged += new
System.EventHandler(this.radioButton1_CheckedChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(216, 182);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.radioButton1.Checked = true; // raises a 'CheckChanged' event,
doesn't raise a 'click' event
}
private void radioButton1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Click");
}
private void button1_Click(object sender, System.EventArgs e)
{
this.radioButton1.Checked = !this.radioButton1.Checked;
}
private void radioButton1_CheckedChanged(object sender, System.EventArgs
e)
{
MessageBox.Show("CheckChanged");
}
}
}