在运行时显示 MaskedTextBox.Mask 属性的设计时弹出窗体

发布于 2024-08-11 12:01:06 字数 134 浏览 3 评论 0原文

有谁知道是否可以打开一个弹出表单“输入掩码”,当您想要更改 MaskedTextBox 编辑器的 Mask 属性并在设计时单击该属性右侧的详细信息按钮时,会显示该弹出表单?

我想在应用程序的运行时使用相同的形式,并将其结果用于掩码字符串。

Does anybody know if it's possible to open a pop-up form "Input Mask" which is displayed when you want to change Mask property of MaskedTextBox editor and you click on the details button on the right side of this property in design-time?

I'd like to use the same form in run-time in an application and use its result for mask string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

潜移默化 2024-08-18 12:01:06

该对话框在System.Design.dll 中定义,名为“MaskDesignerDialog”。它是内部的,因此您不能直接使用它。反射可以绕过这个。使用示例表单进行尝试,在表单上放置一个 Button 和一个 MaskedTextBox。使表单的代码如下所示:

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;

namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e) {
            Assembly asm = Assembly.Load("System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            Type editor = asm.GetType("System.Windows.Forms.Design.MaskDesignerDialog");
            ConstructorInfo ci = editor.GetConstructor(new Type[] { typeof(MaskedTextBox), typeof(System.ComponentModel.Design.IHelpService) });
            Form dlg = ci.Invoke(new object[] { maskedTextBox1, null }) as Form;
            if (DialogResult.OK == dlg.ShowDialog(this)) {
                PropertyInfo pi = editor.GetProperty("Mask");
                maskedTextBox1.Mask = pi.GetValue(dlg, null) as string;
            }
        }
    }
}

The dialog is defined in System.Design.dll, named "MaskDesignerDialog". It is internal so you can't use it directly. Reflection can bypass that. Try it out with a sample form, drop a Button and a MaskedTextBox on the form. Make the form's code look like this:

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;

namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e) {
            Assembly asm = Assembly.Load("System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            Type editor = asm.GetType("System.Windows.Forms.Design.MaskDesignerDialog");
            ConstructorInfo ci = editor.GetConstructor(new Type[] { typeof(MaskedTextBox), typeof(System.ComponentModel.Design.IHelpService) });
            Form dlg = ci.Invoke(new object[] { maskedTextBox1, null }) as Form;
            if (DialogResult.OK == dlg.ShowDialog(this)) {
                PropertyInfo pi = editor.GetProperty("Mask");
                maskedTextBox1.Mask = pi.GetValue(dlg, null) as string;
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文