c#WinForms是否可以获取NumericUpDown文本区域 [英] c# WinForms can you get the NumericUpDown text area

查看:71
本文介绍了c#WinForms是否可以获取NumericUpDown文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取NumericUpDown控件的文本区域?我正在寻找尺寸,以便可以用面板遮盖。我不希望用户能够编辑和选择文本。这可能吗?还是有另一种方法来掩盖文本框中的文本?

Is it possible to get the text area of a NumericUpDown control? I'm looking to get it's size so that I can mask it with a panel. I don't want the user to be able to edit AND select the text. Is this possible? Or is there another way of covering up the text in the text box?

谢谢。

推荐答案

您可以使用Label控件而不是内置的TextBox控件来获取此信息。将新类添加到您的项目中,然后粘贴以下代码。编译。将新控件从工具箱的顶部拖放到表单上。

You can get this by using a Label control instead of the baked-in TextBox control. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

using System;
using System.Windows.Forms;

class UpDownLabel : NumericUpDown {
    private Label mLabel;
    private TextBox mBox;

    public UpDownLabel() {
        mBox = this.Controls[1] as TextBox;
        mBox.Enabled = false;
        mLabel = new Label();
        mLabel.Location = mBox.Location;
        mLabel.Size = mBox.Size;
        this.Controls.Add(mLabel);
        mLabel.BringToFront();
    }

    protected override void UpdateEditText() {
        base.UpdateEditText();
        if (mLabel != null) mLabel.Text = mBox.Text;
    }
}

这篇关于c#WinForms是否可以获取NumericUpDown文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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