Solved

Usercontrol and events?

Posted on 2006-07-10
4
668 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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