First of all I would like to thank you for your reply Mike.
I derived from Button and the same thing happened, however when I place two regular Button components on the same form the same thing happens. Even creating a new solution and adding some buttons to the form and setting AcceptButton to one of the buttons doesn't work. The first button placed on the form is always the default one, what am I forgetting (You dont get this effect do you). I am using Windows XP Pro SP1, I am not Using Visual Styles (aka Windows XP themes).
Also when trying to determine the problem, I changed the Tab Index property so that choosen default button had the highest TabIndex. The buttons then functioned the way I expected.
To test this I placed two buttons on a form button1 and button2, then I placed a checkbox1 on the form. After this I placed another four buttons on the form. I set the forms AcceptButton to button2, this seemed to work in the designer. I then set a method to the OnClick event in button2 so that it would display a message box saying clicked.
I executed my program and pressed the spacebar and saw that button1 was the currently selected button. I exited the program and changed the TabIndex values of button1, button2 and checkbox1 so that checkbox1 was 0, button2 was 1 and button1 was 2. Executed my program and the checkbox responded to my key presses.
Seems to me that te form is setting the default control to whatever the control with the lowest TabIndex value is.
I am fairly sure that my implementation of IButtonControl is correct and I am not setting some property on the form correctly but here it is anyway.
void IButtonControl.NotifyDefault(bool isDefault) { defaultButton=isDefault;
//isDefault is a field declared as a private bool. This is used when painting the button to //determine how the button is painted. If I am right this function should be called by the form. Invalidate(); }
public void PerformClick() { OnClick(EventArgs.Empty); }
[Browsable(true),DefaultValue(typeof(DialogResult), "DialogResult.None"),Description("Specifies the dialog result that this button will return when a form is closed by clicking it."),Category("Behavior")] public DialogResult DialogResult { get { return dialogResult; } set { dialogResult=value; } }
Again any help is appreciated. |