Solved

Usercontrol and events?

Posted on 2006-07-10
4
653 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks.. all
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now