How to programmatically change WindowWorkspaceSetting.AcceptButton?

Jul 23, 2008 at 10:36 AM
Hi,

I am setting WindowWorkspaceSetting.AcceptButton to Ok button on load. I want to change the WindowWorkspaceSetting.AcceptButton to some other button present in the screen, based on some condition. The value for WindowWorkspaceSetting.AcceptButton is getting updated.

But on click of Enter Key, the WindowWorkspaceSetting.AcceptButton is not getting activated.

The code I am working on is below.

// On Load
public void InitSmartPartInfo()
{
smartPartInfo.Keys[WindowWorkspaceSetting.AcceptButton] = btnOK;
}

private void textbox1_Enter(object sender, EventArgs e)
{
smartPartInfo.Keys[WindowWorkspaceSetting.AcceptButton] = btnSearch;
}

private void textbox1_Leave(object sender, EventArgs e)
{
smartPartInfo.Keys[WindowWorkspaceSetting.AcceptButton] = btnOK;
}

private void textbox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter)
    {
        // do some action
       // call btnSearch Event Handler
    }
}

In the above code, in keydown event, Enter Key is not getting activated.

Please help in solving this problem.

Thanks in advance.