Solved

Usercontrol and events?

Posted on 2006-07-10
4
657 Views
Last Modified: 2011-04-21
hi there,

Can anybody help?

When designing a usercontrol (vs2003 winforms) what events are available by default to anybody who uses the usercontrol on a form?

For example if i have created a new usercontrol out of some textboxes and checkboxes... if i want to access properties/events of the textboxes and checkboxes within the user control - what shoyuld i do =?

if it available by default or do i have to do something?

Anybody provide me with some details, that would be great....

Thanks

Ian
0
Comment
Question by:ianinspain
4 Comments
 
LVL 2

Assisted Solution

by:shy_talk
shy_talk earned 125 total points
ID: 17073175
You create properties of your own by viewing the code window for the UserControl and creating properties like the one below (courtesy of the help file).  For example, if your control needs a Text property and contains a TextBox control, you create a Text property like the ClockBackColor property below, and return, say, TextBox1.Text where it the code below returns colBColor. Similarly with events. You create event procedures  in your UserControl code, much like the ones you create inside a Windows Form and raise the UserControl's events from inside there.

Hope this helps somehow.

// Declares the name and type of the property.
public Color ClockBackColor
{
    // Retrieves the value of the private variable colBColor.
    get
    {
        return colBColor;
    }
    // Stores the selected value in the private variable colBColor, and
    // updates the background color of the label control lblDisplay.
    set
    {
        colBColor = value;
        lblDisplay.BackColor = colBColor;  
    }
}
// Provides a similar set of instructions for the foreground color.
public Color ClockForeColor
{
    get
    {
        return colFColor;
    }
    set
    {
        colFColor = value;
        lblDisplay.ForeColor = colFColor;
    }
}
0
 
LVL 11

Accepted Solution

by:
Agarici earned 250 total points
ID: 17073246
you can do a couple of things:
1. make all texboxes checkboxes etc public and use <YourCtrlInstance>.TextBox1.Text
2. make pubic properties to help you change/access something on one of the controls in your usercontrol like this:
public string MyTextBoxText
{
   get{return this.textBox1.text;}
   set{this.textbox1.text = value;}
}

you can do the same for events.

hth,
A.
0
 
LVL 11

Assisted Solution

by:vo1d
vo1d earned 125 total points
ID: 17074287
if you wanna have support for the property page in the designer, use some attributs for that on your public properties like that:

[System.ComponentModel.Browsable(true)]
[System.ComponentModel.DefaultValue(typeof(Color), "Color.White")]
[System.ComponentModel.Category("MyCategory")]
[System.ComponentModel.Description("Provides a similar set of instructions for the foreground color.")]
public Color ClockForeColor
{
    get
    {
        return colFColor;
    }
    set
    {
        colFColor = value;
        lblDisplay.ForeColor = colFColor;
    }
}
0
 

Author Comment

by:ianinspain
ID: 17147123
thanks.. all
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question