现在我要双击其他label的时候,不管修改是否完成,这个textbox也变回label,怎么做?说不明白,还是来代码吧,但很多人不耐烦看代码
Label hjlbl = new Label();private void label1_DoubleClick(object sender, EventArgs e)
{
TextBox hjtx = new TextBox();
Label hjlbl = sender as Label;
hjlbl.Visible = false;
hjtx.Location = hjlbl.Location;
hjtx.Size = hjlbl.Size;
hjtx.Text = hjlbl.Text;
hjtx.Visible = true;
hjtx.KeyDown += new KeyEventHandler(hjtx_KeyDown);
this.Controls.Add(hjtx);
} void hjtx_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
TextBox hjtx = sender as TextBox;
hjtx.Visible = false;
hjlbl.Text = hjtx.Text;
hjlbl.Visible = true;
this.Controls.Add(hjlbl);
}
}
Label hjlbl = new Label();private void label1_DoubleClick(object sender, EventArgs e)
{
TextBox hjtx = new TextBox();
Label hjlbl = sender as Label;
hjlbl.Visible = false;
hjtx.Location = hjlbl.Location;
hjtx.Size = hjlbl.Size;
hjtx.Text = hjlbl.Text;
hjtx.Visible = true;
hjtx.KeyDown += new KeyEventHandler(hjtx_KeyDown);
this.Controls.Add(hjtx);
} void hjtx_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
TextBox hjtx = sender as TextBox;
hjtx.Visible = false;
hjlbl.Text = hjtx.Text;
hjlbl.Visible = true;
this.Controls.Add(hjlbl);
}
}
使用textbox显示label
void hjtx_KeyDown(object sender, KeyEventArgs e)
{
TextBox hjtx = sender as TextBox;
hjlbl.Text = hjtx.Text;
if (e.KeyCode == Keys.Enter)
{
hjtx.Visible = false;
hjlbl.Visible = true;
this.Controls.Add(hjlbl);
}
}我想了一下,觉得应该在键盘动作的时候就给hjlbl.Text赋值,那就应该是这样现在的关键问题是,我如何调用hjtx_KeyDown,在哪里调用?
问题改一下,要求只要鼠标在别的地方按下就改为label,谁能告诉我怎么做吧,具体一点好吧。这两天我都在搞那个什么LEVER,楞没搞出正确的效果
private void textBox1_Leave(object sender, EventArgs e)
{
textBox1.Visible = false;
}窗体其他部分的Click事件写上XXX.Focus()