验证/编辑事件未在类库窗口窗体中触发
我正在使用 Visual Studio 2010 和 C# 开发 Word 2010 插件。
我创建了一个简单的表单,包含两个文本框和一个“确定”按钮。
“确定”按钮的原因验证属性设置为 true。
两个文本框的 CausesValidation 属性都设置为 false,并且设置了它们的 Validating 和 Validated 属性。这样,它们仅在单击“确定”按钮时验证,而不是在焦点更改时验证。
如果在 Word 加载项中定义了表单代码,则当单击“确定”按钮时,验证和已验证事件将按预期运行。我希望使表单可重用,因此我将表单移至单独的类库中。该表单基本上按预期工作,但验证和已验证事件从未使用上述配置运行。
有人知道为什么会出现这种情况吗?这是一个错误吗?
I'm developing a Word 2010 add in using Visual Studio 2010, and C#.
I've created a simple form, with two textboxes, and an Ok button.
The Ok button's Causes validation property is set to true.
Both textboxes CausesValidation property is set to false, and their Validating and Validated properties are set. This is so that they are only validated when the Ok button is clicked, and not when focus is changed.
If the form code is defined within the Word add in, the validating and validated events run as expected - when the Ok button is clicked. I wanted to make the form reusable, so I moved the form into a separate class library. The form largely works as expected but the validating and validated events never run with the above configuration.
Does anybody know why this is the case? Is it a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您执行以下操作,您似乎可以让事情正常工作:
1)将基本表单的 AutoValidate 属性设置为“禁用”。
2) 将文本框上的 CausesValidation 属性设置为 true。
3)在按钮点击中调用this.ValidateChildren()方法。
It seems that you can get things working if you:
1) Set the AutoValidate property of the base form to Disable.
2) Set the CausesValidation property on the textbox to true.
3) Call the this.ValidateChildren() method in the button click.