C#中的自定义GroupBox,带有2个文本框和1个按钮 [英] Custom GroupBox in C# with 2 text box and 1 button

查看:708
本文介绍了C#中的自定义GroupBox,带有2个文本框和1个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建自定义组框,这是我的代码

i am trying to make a custom group box and here is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace CustomLogin
{
    public partial class CLogin : GroupBox
    {
        TextBox TBOX = null;
        TextBox PBOX = null;
        Label lblUName = null;
        Label lblPass = null;
        Button btnLog = null;

        Color waterMarkColor = Color.Red;
        Color forecolor;
        Font font;
        Font waterMarkFont;

        //Color waterMarkColor = Color.Red;
        string UText = "Username";
        string PText = "Password";
        string btnLogin = "&Login";

        public CLogin()
        {
            InitializeComponent();

        }

        public CLogin(IContainer container)
        {
            this.forecolor = this.ForeColor;
            this.ForeColor = this.waterMarkColor;
            this.font = this.Font;

            TBOX = new TextBox();
            PBOX = new TextBox();

            lblUName = new Label();
            lblPass = new Label();

            lblUName.Text = UText;
            lblPass.Text = PText;

            btnLog = new Button();

            btnLog.Text = btnLogin;

            this.Controls.Add(TBOX);
            this.Controls.Add(PBOX);

            this.Controls.Add(lblUName);
            this.Controls.Add(lblPass);

            this.Controls.Add(btnLog);

            TBOX.Location = new Point(59, 39);
            PBOX.Location = new Point(59, 77);

            lblUName.Location = new Point(18, 42);
            lblPass.Location = new Point(18, 80);

            btnLog.Location = new Point(83, 104);
        
            container.Add(this);

            InitializeComponent();
        }
        

        [Browsable(true)]
        [Category("Extended Properties")]
        [Description("sets TextBox text")]
        [DisplayName("Title")]
        public new string Text
        {
            get
            {
                //required for validation for Text property
                return base.Text.Replace(this.UText, string.Empty);
            }
            set
            {
                base.Text = value;
            }

        }

        [Browsable(true)]
        [Category("Extended Properties")]
        [Description("sets TextBox text")]
        [DisplayName("Log-By")]
        public new string username
        {
            get
            {
                //required for validation for Text property
                return lblUName.Text.Replace(this.UText, string.Empty);
            }
            set
            {
                lblUName.Text = value;
            }

        }
    }
}



问题是我拿自定义组合框时在winfrom从工具箱它显示只有组框它没有显示文本框和按钮,但当我调试我的项目并运行它所有文本框和按钮显示.....我想显示文本框和winform上的按钮当我采取自定义组框在winform上从工具箱中...... plz帮我plz


and the problem is that when i take my custom groupbox on winfrom from toolbox its show only group box it is not showing textboxs and button but when i debug my project and run it all textbox and button are shown..... i want to show textboxs and button on winform when i take custom groupbox on winform from tool box...... plz help me plz

推荐答案



您是否在代码中注意到了这一点。



Hi,
Have you noticed this in your code.

TextBox TBOX = null;
TextBox PBOX = null;
Label lblUName = null;
Label lblPass = null;
Button btnLog = null;





你没有''初始化控件,你在构造函数中初始化它们,所以它不会出现在你的设计器中。



顺便提一下你需要查看C#命名约定

http://msdn.microsoft.com/en -us / library / vstudio / ff926074.aspx [ ^ ]



http://msdn.microsoft.com/en-us/library/xzf533w0%28v=vs.71%29.aspx [ ^ ]



你的命名习惯很糟糕。



问候

Jegan



you haven''t initialized the controls, you are initializing them in your constructor, so it will not show up in you designer.

By the way you do need to look up on the C# naming convention
http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx[^]

http://msdn.microsoft.com/en-us/library/xzf533w0%28v=vs.71%29.aspx[^]

Your naming habit is terrible.

Regards
Jegan


这篇关于C#中的自定义GroupBox,带有2个文本框和1个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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