画面上有如下控件:日期1______ 数字1________
日期2______ 数字2________
日期3______ 数字3________
退出按钮问题:
假设我原来在入力[数字2],然后点[退出按钮]后会提示[是否确定退出?]信息,
如果我点[否],如何让焦点回到任意一个之前所在的控件([数字2])?
日期2______ 数字2________
日期3______ 数字3________
退出按钮问题:
假设我原来在入力[数字2],然后点[退出按钮]后会提示[是否确定退出?]信息,
如果我点[否],如何让焦点回到任意一个之前所在的控件([数字2])?
不好意思,没说清楚,win的
应该就可以了
多谢你的建议,可是我这个画面上面有200多个完全不同的控件阿,
而且不象我举的例子那样都是类似的控件哦。倒霉。
TextBox lastEditting = null;
void OnTextBoxLeft(object sender, EventArgs e)
{
lastEditting = sender as TextBox; //<---
} private void Form1_Load(object sender, EventArgs e)
{
//TextBox textBox1;
//TextBox textBox2;
textBox1.LostFocus += OnTextBoxLeft;
textBox2.LostFocus += OnTextBoxLeft;
} protected override void OnFormClosing(FormClosingEventArgs e)
{
if (MessageBox.Show("quit?", null, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
e.Cancel = true;
if (lastEditting != null)
{
lastEditting.Focus();
lastEditting.SelectAll();
} }
}
{
protected override void OnLostFocus(EventArgs e)
{
(this.Parent as Form1).lastEditting = this;
base.OnLostFocus(e);
}
}
var textobj;
function focblur(ob){
textobj = ob;
}然后点击退出按钮时,代码如下
function dd(){
if(confirm("是否确定退出?")==false)
textobj.focus();
}
//winform
thisExitButton_Click(sender,e)
{
string message = "是否确定退出?";
string caption = "";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show(this, message, caption, buttons,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign); if(result == DialogResult.No)
{
// Focus
UserCountrol.Focus();
}
else
{
//点击是的操作
}}
{
if (MessageBox.Show("Exit", "", MessageBoxButtons.YesNo) == DialogResult.No)
c.Focus();
else
this.Close();
}
Control c;
private void 退出按钮_MouseEnter(object sender, EventArgs e)
{
c=this.ActiveControl;
}
尝试了一下大家的建议,感觉h_w_king的方案非常不错,开销和代码都最省,多谢了。感谢大家的参与,结贴!
控件多,我得每一类控件都要加一个事件,累。>对了,顺便问下楼方,你这么多控件.呈现的时候,有闪的现象吗?
有,不过不明显。