验证和撤消 [英] Validation and Undo

查看:72
本文介绍了验证和撤消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于WinForms如何在

控件的验证期间处理撤消更改的一般问题,如果它完成的话。

更改控件之后'' s值,如果确定数据为
无效,那么在控件的验证事件处理程序中,设置e.Cancel =

true将防止违规控制从失去焦点直到

中的数据控制良好。


如果用户想要恢复到原始数据,比如按ESC,那么

表单有这种操作的任何类型的默认行为(即:

撤消更改)?或者我是否必须手动编程整个撤消过程




这可能需要覆盖ProcessCmdKey并寻找ESC,并且

在控件获得焦点之前存储控件的值,这样我就可以在ESC被击中后重置它。


我以为这是一个默认行为由于某种原因,但测试

这个显示我的TextBox不是这样的。


有什么建议可以更好地通过实现一个简单的撤消?

General question about how WinForms handles undoing a change during a
control''s validation, if it does at all.
After a change to a control''s value, if the data is determined to be
invalid, then in the control''s Validating event handler, setting e.Cancel =
true will prevent the offending control from losing focus until the data in
the control is good.

If the user wants to revert to the original data, say by hitting ESC, does
the form have any kinds of default behaviours for this kind of action (ie:
undoing a change)? Or do I have to program this whole undo process
manually?

This could entail overriding the ProcessCmdKey and looking for ESC, and
storing the value of the control before the control receives focus so I can
reset it after ESC is hit.

I had thought that this was a default behaviour for some reason, but testing
this out reveals this not to be the case for my TextBox.

Are there any suggestions for a better way to implement a simple undo?

推荐答案

John,


TextBox具有撤销功能,但你不能不知道有多少变化

,所以你不能解开撤销堆栈。


相反,你会去的数据源并获取原始的

值(或者,在绑定发生时存储原始值)。这是唯一的

方式,你可以确定原始值。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam .guard.caspershouse.com


" John Richardson" < J3 ********* @ nospam.ca>在消息中写道

新闻:uU ************** @ TK2MSFTNGP11.phx.gbl ...
John,

The TextBox has undo capability, but you don''t know how many changes
have been made, so you just can''t unwind the undo stack.

Rather, you will have you go to the data source and get the original
value (or, store the original value when binding occurs). That''s the only
way you can be sure of the original value.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Richardson" <j3*********@nospam.ca> wrote in message
news:uU**************@TK2MSFTNGP11.phx.gbl...
关于WinForms如何的一般问题在
控件的验证过程中处理撤消更改(如果有的话)。
更改控件的值后,如果确定数据无效,然后在控件的验证事件处理程序中,设置e.Cancel
= true将防止违规控件失去焦点,直到控件中的数据好。

如果用户想要恢复到原始数据,比如通过按ESC,表单是否有任何类型的默认行为用于此类操作(即:撤消更改)?或者我是否必须手动编程整个撤消过程?

这可能需要覆盖ProcessCmdKey并查找ESC,并在控件接收之前存储控件的值因此我可以在ESC被击中后重置它。

由于某些原因,我原本认为这是一种默认行为,但是测试这一点后发现这不是我的TextBox的情况。

是否有任何建议可以更好地实现简单撤消?
General question about how WinForms handles undoing a change during a
control''s validation, if it does at all.
After a change to a control''s value, if the data is determined to be
invalid, then in the control''s Validating event handler, setting e.Cancel
= true will prevent the offending control from losing focus until the data
in the control is good.

If the user wants to revert to the original data, say by hitting ESC, does
the form have any kinds of default behaviours for this kind of action (ie:
undoing a change)? Or do I have to program this whole undo process
manually?

This could entail overriding the ProcessCmdKey and looking for ESC, and
storing the value of the control before the control receives focus so I
can reset it after ESC is hit.

I had thought that this was a default behaviour for some reason, but
testing this out reveals this not to be the case for my TextBox.

Are there any suggestions for a better way to implement a simple undo?



> TextBox具有撤消功能


这仅适用于数据绑定上下文吗?我查看了

文本框的界面,我无法看到控件的先前值在哪里

存储...而且我不是需要一个完整的撤消历史。话虽这么说,我会自己构建它,但是为了给自己一些灵活性。

Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在

消息新闻:uF ************* @ tk2msftngp13.phx.gbl ...
>The TextBox has undo capability

Is this only for a databound context? I looked at the interface for the
textbox and I couldn''t see where the previous value of the control would be
stored... and I don''t need a whole undo history. That being said, I''ll
probably build it myself anyways to give myself some flexibility.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uF*************@tk2msftngp13.phx.gbl...
John,

TextBox具有撤消功能,但您不知道已经进行了多少更改,因此您无法解除撤消堆栈。

相反,您将获得数据源并获取原始值(或者,在发生绑定时存储原始值)。这是唯一可以确定原始价值的方式。

希望这会有所帮助。

-
- Nicholas Paldino [ .NET / C#MVP]
- mv*@spam.guard.caspershouse.com

John Richardson < J3 ********* @ nospam.ca>在消息中写道
新闻:uU ************** @ TK2MSFTNGP11.phx.gbl ...
John,

The TextBox has undo capability, but you don''t know how many changes
have been made, so you just can''t unwind the undo stack.

Rather, you will have you go to the data source and get the original
value (or, store the original value when binding occurs). That''s the only
way you can be sure of the original value.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Richardson" <j3*********@nospam.ca> wrote in message
news:uU**************@TK2MSFTNGP11.phx.gbl...
关于WinForms如何处理撤消更改的一般问题在
控件的验证期间,如果它确实存在。
在更改控件的值后,如果确定数据无效,则在控件中''验证事件处理程序,设置e.Cancel
= true将防止有问题的控件失去焦点,直到控件中的数据良好为止。

如果用户想要要恢复到原始数据,比如按ESC键,
表单是否有这种动作的任何默认行为(即:撤消更改)?或者我是否必须手动编程整个撤消过程?

这可能需要重写ProcessCmdKey并查找ESC,并在控件接收之前存储控件的值因此我可以在ESC被击中后重置它。

由于某些原因,我原本认为这是一种默认行为,但是测试这一点后发现这不是我的TextBox的案例。

是否有任何建议可以更好地实现简单撤消?
General question about how WinForms handles undoing a change during a
control''s validation, if it does at all.
After a change to a control''s value, if the data is determined to be
invalid, then in the control''s Validating event handler, setting e.Cancel
= true will prevent the offending control from losing focus until the
data in the control is good.

If the user wants to revert to the original data, say by hitting ESC,
does the form have any kinds of default behaviours for this kind of
action (ie: undoing a change)? Or do I have to program this whole undo
process manually?

This could entail overriding the ProcessCmdKey and looking for ESC, and
storing the value of the control before the control receives focus so I
can reset it after ESC is hit.

I had thought that this was a default behaviour for some reason, but
testing this out reveals this not to be the case for my TextBox.

Are there any suggestions for a better way to implement a simple undo?



" John Richardson" < J3 ********* @ nospam.ca> écritdansle message de news:

O
"John Richardson" <j3*********@nospam.ca> a écrit dans le message de news:
O


这篇关于验证和撤消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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