Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Very odd Windows Form behavior - what could it be?

Hi All,

I'm experiencing some very odd behavior in a form and for the life of me I can't figure out the cause.

Here's a simplified setup: Assume that I have a Form1 which contains a button which creates a Form2 object and then calls Form2.ShowDialog(). On Form2 there is another button which creates a Form3 object and then calls Form3.ShowDialog().

Two odd things are happeneing:

1) When I close Form3, Form2 immediately hides. This happens even if Form3 is a new empty form, so clearly it is something in Form2. The code to open both forms is simply (with the appropriate form name):

        Dim frm As New Form2

Creating an empty project to test this works fine, so it's obviously something in one of my forms causing this odd behavior.

2) On Form3, I have two radio buttons. When the Form_Load event sets the checked property on one of them the RadioButton.Click event is thrown (and there hasn't been a mouse click). The .click event is acting as if it is the .CheckedChanged event.

Both of these have me baffled and no amount of Googling has turned up anything. I'm assuming that this is something elemental and simple that I'm overlooking, but I simply cannot find it. Since they are both so odd I'd assume that they're related, but maybe not. What could is be? Any ideas what to look at?

Thanks in advance,

Sunday, October 24, 2004

Check the forms' AcceptButton/CancelButton properties. Form2's button might have this set.

Duncan Smart
Monday, October 25, 2004

Thanks for the idea Duncan, but that's not it. None of the forms have the AcceptButton or CancelButtons set, and in a simple three form test I set up setting them didn't cause that behavior.

Monday, October 25, 2004

Ok, I figured out the form closing issue. Somehow the following line was in the definition of the button I was using to launch the form:

        Me.btnRecordResults.DialogResult = System.Windows.Forms.DialogResult.Cancel

That's the line put in by the designer when you set a form's CancelButton. I'm not sure how it go there, but I've at least isolated the cause.

Now to figure out why in the hell the click event is being called on those radio buttons.

Monday, October 25, 2004

*  Recent Topics

*  Fog Creek Home