有一个textbox控件和一个combobox控件,要求焦点在textbox上时显示combobox控件并将焦点设到combobox上面,当combobax失去焦点后把item值赋给textbox控件,在.net2002上已实现,但在.net2003上却不行,请大家帮帮忙了 
代码如下:
private void txtUnit_Enter(object sender, System.EventArgs e)
{
TextBox box = (TextBox)sender;
this.cbmUnit.Location=box.Location;
this.cbmUnit.BringToFront();
this.cbmUnit.Visible = true;
this.cbmUnit.Focus();
}
private void cbmUnit_Leave(object sender, System.EventArgs e)
{
if(((ComboBox)sender).SelectedIndex != -1)
{
string s = ((ComboBox)sender).SelectedItem.ToString();
this.txtUnit.Text=(s=="<无>"?"":s);
this.txtUnit.Visible=true;
this.cbmUnit.Visible = false;
}
}

解决方案 »

  1.   

    用这两个事件就可以了。不用你写得那么复杂吧。
    private void textBox2_Enter(object sender, System.EventArgs e)
    {
    this.comboBox1.Focus();
    } private void comboBox1_Leave(object sender, System.EventArgs e)
    {
    this.textBox2.Text = this.comboBox1.Text;
    }
      

  2.   

    是两个事件啊 ,你还要考虑combobox和textbox重叠以及焦点失去时把combobox隐藏
    另,2002下可以的,2003下不行,不信你可以试试