Custom User Control properties

Alexthemaster

Newcomer
Joined
Dec 15, 2008
Messages
4
Hi,
I've been looking for a while on internet to find an answer to this.
the thing is:
I want to access a Custom user control property from the parent form, to see if the login and password entered is true or false(if it exists), but i'm not very sure how to add a property or exactly how to proceed. here's what I have, I guess it's a start:

Code:
        [Description("Validate the account"),
        Category("Values"),
        DefaultValue(false),
        Browsable(true)]
        public bool Retvalue
        {

        }
(This is not web)
 
Found the answer myself:

Code:
// In the user control

        [Category("Configuration"), Description("This is the password"), Browsable(true)]
        public string Password
        {
            get;
            set;
        }
or
        [Category("Configuration"), Description("value"), Browsable(true), DefaultValue(false)]
        public bool valacc
        {
            get;
            set;
        }

And you can add events:

Code:
//In the user control
namespace controllib
{
    public delegate void logindelg(object sender, EventArgs e);
    public partial class Logincontrol : UserControl
    {
        public event logindelg login_click;
        public event logindelg Cancel_click;
[...]
//In the main form
private void login1_login_click(object sender, EventArgs e)
        {
            if (login1.valacc == true)
            {
                MessageBox.Show("Account activated");
            }
        }
 
Last edited:
The property itself would be a normal read only property (i.e. no set method).
C#:
[Description("Validate the account"),
Category("Values"),
DefaultValue(false),
Browsable(true)]
        public bool Retvalue
        {
         get {return <whatever>};
        }
The Browsable(true) isonly required if you need this to appear in the property grid at design time - otherwise set it to false and in that case the Category and Description are also un-needed.
 
Back
Top