Solved

Usercontrol and events?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

761 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