验证/编辑事件未在类库窗口窗体中触发

发布于 2024-09-27 10:26:56 字数 463 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪眸﹌ 2024-10-04 10:26:56

如果您执行以下操作,您似乎可以让事情正常工作:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文