TabPage 验证单击当前选定选项卡时触发的事件
我正在做 如何防止用户更改 TabControl 中选定的选项卡页?
一切正常。但是,如果我当前选择了 tabpage1 并且用户单击 tabpage1 本身,则会发生 tabpage1 的验证事件。稍后,当用户单击 tabpage2 时,tabpage1 的验证事件不会触发。
发生的情况是,如果我在 tabpage1 的验证事件中执行 e.Cancel
,在上述情况下,当用户错误地单击 tabpage1 且已经选择了 tabpage1 时,它会提示用户“您想留下吗?”在当前选项卡上保存数据或从当前选项卡移动?”。如果用户点击Stay
但不进行任何更改。然后,当他正确单击 tabpage2 时,tabpage1 的 Validating 事件不会触发。
我已在此处上传了示例应用程序。您可以运行并查看行为以正确理解问题
I'm doing things as said in How do I prevent the user from changing the selected tab page in a TabControl?
Things are working fine. But the validating event of tabpage1 occurs if I've tabpage1 is currently selected and user clicks on tabpage1 itself. and later when user clicks on tabpage2 validating event for tabpage1 doesn't fire.
What happens is if I do e.Cancel
in validating event of tabpage1, in the above case, when user clicks on tabpage1 by mistake having tabpage1 already selected, it will prompt user that "Do you want to stay on current tab to save data or move from the current tab?". and if user clicks Stay
but doesn't do any changes. And then when he correctly clicks tabpage2, Validating event of tabpage1 is not firing.
I've uploaded the sample application here. You can run and see the behavior to properly understand the problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
TabControl.Selecting 事件
代替。像这样使用它:
Use
TabControl.Selecting Event
instead.Use it like this:
这与验证应该的行为很相似,只是与标签页的匹配不太幸运。
您可以使用 Selecting/Selected 事件并自己编写更多逻辑。或者放弃选项卡页面或单独验证它们的想法。
This is kinf of how validating should behave, it's just not a lucky match with tabpages.
You could use the Selecting/Selected events and write some more logic yourself. Or give up on either tabpages or the idea that they are to be validated individually.