如果在子表单上取消,请关注字段 [英] Focus on field if Cancel on child form

查看:105
本文介绍了如果在子表单上取消,请关注字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子窗体frmDataEntry调用另一个子窗体frmDealerSearch。

如果用户点击frmDealerSearch上的取消,我想关闭

frmDealerSearch并放置焦点在frmDataEntry上的txtDealerNum上。


这是我的代码。


公共类frmDataEntry:System.Windows.Forms.Form

{

private void txtDealerNum_Leave(object sender,System.EventArgs e)

{

frmDealerSearch f = new frmDealerSearch();

f.ShowDialog();

}


}

公共类frmDealerSearch:System.Windows .Forms.Form

{

private void cmdCancel_Click(object sender,System.EventArgs e)

{

this.Close();

}

}

I have a child form frmDataEntry call up another child form frmDealerSearch.
If the user clicks on cancel on frmDealerSearch, I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
}

推荐答案

使用DialogResult -


公共类frmDataEntry:System.Windows.Forms.Form

{

private void txtDealerNum_Leave(object sen der,System.EventArgs e)

{

frmDealerSearch f = new frmDealerSearch();

if(f.ShowDialog()== DialogResult 。取消)

{

//设定焦点

}

}

}

公共类frmDealerSearch:System.Windows.Forms.Form

{

private void cmdCancel_Click(object sender,System .EventArgs e)

{

this.DialogResult = DialogResult.Cancel;

this.Close();

}

}

-

Adam Clauss


" Mike L" <钙*** @ nospam.nospam>在留言中写道

news:21 ********************************** @ microsof t.com ...
Use DialogResult -

public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
if (f.ShowDialog() == DialogResult.Cancel)
{
//set focus here
}
}

}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
--
Adam Clauss

"Mike L" <Ca***@nospam.nospam> wrote in message
news:21**********************************@microsof t.com...
我有一个子窗体frmDataEntry调用另一个子窗体
frmDealerSearch。
如果用户在frmDealerSearch上点击取消,我想关闭
frmDealerSearch并将重点放在frmDataEntry上的txtDealerNum上。

这是我的代码。

公共类frmDataEntry:System.Windows.Forms.Form
{<私有空txtDealerNum_Leave(对象发送者,System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}

}

公共类frmDealerSearch:System.Windows.Forms.Form
{void void cmdCancel_Click(object sender,System.EventArgs e)
{
this.Close();
}
}
I have a child form frmDataEntry call up another child form
frmDealerSearch.
If the user clicks on cancel on frmDealerSearch, I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
}



在frmDealerSearch上,确保取消lButton属性设置为

表单取消按钮。另外,将此

按钮的DialogResult属性设置为Cancel。另外,你从cmdCancel_Click中删除this.Close()为

它将自动发生。


接下来,你想知道这个从f.ShowDialog()返回值,并且

基于它将焦点设置为txtDealerNum,非常类似于:


if(f.ShowDialog( )== DialogResult.Cancel)

{

txtDealerNum.Focus();

}


Brendan

" Mike L"写道:
On frmDealerSearch, make sure that the CancelButton property is set to the
forms Cancel Button. In addition, set the DialogResult property of this
button to Cancel. Also, you remove the this.Close() from cmdCancel_Click as
it will occur automatically.

Next, youa??d want to be aware of the return value from f.ShowDialog(), and
based on it act to set the focus to txtDealerNum, much like:

if( f.ShowDialog() == DialogResult.Cancel )
{
txtDealerNum.Focus();
}

Brendan
"Mike L" wrote:
我有一个子窗体frmDataEntry调用另一个子窗体frmDealerSearch。
如果用户点击frmDealerSearch上的取消,我想关闭
frmDealerSearch和将重点放在frmDataEntry上的txtDealerNum上。

这是我的代码。

公共类frmDataEntry:System.Windows.Forms.Form
{
私有void txtDealerNum_Leave(object sender,System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}
}

公共类frmDealerSearch:System.Windows.Forms.Form
私有空cmdCancel_Click(对象发送者,System.EventArgs e)
{
this.Close();
}
}
I have a child form frmDataEntry call up another child form frmDealerSearch.
If the user clicks on cancel on frmDealerSearch, I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
}



不起作用,f.ShowDialog()回来了<过载>和DialogResult.Cancel

回复为无。


" Adam Clauss"写道:
Doesn''t work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel
comes back as None.

"Adam Clauss" wrote:
使用DialogResult -

公共类frmDataEntry:System.Windows.Forms.Form
私有空txtDealerNum_Leave(对象sender,System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
if(f.ShowDialog()== DialogResult.Cancel)
{
//设置焦点
}
}


公共类frmDealerSearch:System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender,System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}

-
Adam Clauss

Mike L <钙*** @ nospam.nospam>在消息中写道
新闻:21 ********************************** @ microsof t.com。 ..
Use DialogResult -

public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
if (f.ShowDialog() == DialogResult.Cancel)
{
//set focus here
}
}

}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
--
Adam Clauss

"Mike L" <Ca***@nospam.nospam> wrote in message
news:21**********************************@microsof t.com...
我有一个子窗体frmDataEntry调用另一个子窗体
frmDealerSearch。
如果用户点击frmDealerSearch上的取消,我想关闭
frmDealerSearch和将重点放在frmDataEntry上的txtDealerNum上。

这是我的代码。

公共类frmDataEntry:System.Windows.Forms.Form
{
私有void txtDealerNum_Leave(object sender,System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}
}

公共类frmDealerSearch:System.Windows.Forms.Form
私有空cmdCancel_Click(对象发送者,System.EventArgs e)
{
this.Close();
}
}
I have a child form frmDataEntry call up another child form
frmDealerSearch.
If the user clicks on cancel on frmDealerSearch, I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
}




这篇关于如果在子表单上取消,请关注字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆