如何添加按钮,文本框? [英] How to add button to textbox?

查看:297
本文介绍了如何添加按钮,文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个TextBox与右侧的按钮。
我的代码:

I'm trying to make a TextBox with a button on the right side. My code:

public partial class TextBoxButton : TextBox
{
    [Category("Button")]
    [Description("Button in textbox")]
    public Button Button
    {
        get
        {
            return this.btn;
        }
        set
        {
            this.btn = value;
        }
    }

    protected override void OnCreateControl()
    {
        if (!this.Controls.Contains(this.btn))
        {
            this.Controls.Add(this.btn);
            this.btn.Dock = DockStyle.Right;
        }

        base.OnCreateControl();
    }
}



每次当我开始我APPI并设置一些文字或图像中的按钮,它是空的。一些想法?

Everytime when I start my appi and set some text or image in the button it's empty. Some ideas?

最好的问候。

推荐答案

您必须告诉设计师,它也应该序列化按钮的属性:

You have to tell the designer that it should also serialize the properties of the button:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Button Button {
    //...
}

默认是隐藏所以没有按钮的属性将被写入到Designer.cs文件。设置,也就是说,Text属性工作在设计师,但你启动应用程序或重新加载表格后属性值丢失。

The default is Hidden so none of the button properties would be written to the Designer.cs file. Setting, say, the Text property works in the designer but the property value is lost after you start the app or reload the form.

这篇关于如何添加按钮,文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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