Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to make a custom group box and here is my code
C#
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;
            }

        }
    }
}

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
Posted
Updated 15-Mar-13 1:34am
v2

1 solution

Hi,
Have you noticed this in your code.

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


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900