C# 用户控件对外公开属性

public partial class UserMessageControl : UserControl
    {
        public UserMessageControl()
        {
            InitializeComponent();
           
            //为防止由控件重绘引起的闪烁,我们可以启用双缓冲,指定控件的ControlStyles.DoubleBuffer为true。
            //要完全启用双缓冲,必须也要将 UserPaint 和 AllPaintingInWmPaint位数设置为 true
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
        }
        //对外公布属性
        [DefaultValue(typeof(string), ""), Browsable(true), Description("控件中的txtMessage的Text属性"), Category("Action")]
        public string txtMessageTValue
        {

            get
            {
                return txtMessage.Text;
            }
            set
            {
                this.txtMessage.AppendText(value);
            }
        }

        [DefaultValue(typeof(string), ""), Browsable(true), Description("控件中的txtSend的Text属性"), Category("Action")]
        public string txtSendTValue
        {

            get
            {
                return txtSend.Text;
            }
            set
            {
                this.txtSend.Text = value;
            }
        }
        //文本框的滚动条显示设定
        private void txtMessage_TextChanged(object sender, EventArgs e)
        {
            //1.在控件属性中,设置ScrollBars 属性的值为 Vertical
            //2.添加以下代码,进行设定文本改变时,滚动条显示
            txtMessage.ScrollToCaret();
        }

    }

posted @ 2012-12-26 14:38  LiGang  阅读(380)  评论(0编辑  收藏  举报