【发布时间】:2012-10-23 11:52:30
【问题描述】:
我创建了一个 Windows 表单,其中包含一个下拉组合框和某些字段。当从下拉列表中选择任何值时,字段的值会相应更改。我面临的问题是我无法单击 Windows 窗体中的其他任何位置。焦点停留在 ComboBox 下拉菜单上。我使用了其他按钮,例如“打印”,它提供了打印获胜表单中显示的信息的便利。但由于焦点卡在组合框上,我无法单击它。对于组合框,我使用了以下代码:
private void btnPrint_Click(object sender, EventArgs e)
{
try
{
ExistingAccountScreen existingAcctScreen = new ExistingAccountScreen();
FillExistingAppForPrinting(existingAcctScreen);
using (PrintViewer pv=new PrintViewer(existingAcctScreen))
{
pv.ShowDialog();
}
}
catch (Exception ex)
{
AOTHelper.WriteLog(ex);
}
}
下拉点击事件如下,在选择默认选定值以外的值时会产生问题
private void cmbAccountNumber_SelectedIndexChanged(object sender, EventArgs e)
{
ExistingAccountInfo acctInfo = cmbAccountNumber.SelectedItem as ExistingAccountInfo;
if (acctInfo == null)
return;
existingAccountInfoBindingSource.DataSource = ExistingAccountInfo.Get(acctInfo.AccountNumber);
accountStatusBindingSource.DataSource = ExistingAccountInfo.GetExistingStatusCodes(acctInfo.AccountNumber);
}
【问题讨论】:
-
是否有定时器或后台worker控制焦点?你能发布一个代码 sn-p :) 吗?
-
您可以添加 DropDownList 的“OnChange”处理程序的代码吗?
-
尝试将焦点放在您想要的任何控件上 control.Focus = true; (在表格加载)!您想要关注表单加载的控件!
-
@Bazz:我使用了 DropDown List 的 SelectedIndex 事件,仅此而已。可以通过设置其他控件的焦点来完成,但是我只想知道为什么会出现这个问题
-
@Yash 我相信提供代码 sn-p 会更容易检测到问题:)