Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Usercontrol and events?

Posted on 2006-07-10
4
Medium Priority
?
699 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Assisted Solution

by:shy_talk
shy_talk earned 500 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 1000 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

670 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