Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to create user control which have 1 button and 2 labels, first button shows color and told that terminal are connected or not and one labels shows that PC Terminal # or ID and another label is shows how many time left like timer or stop watch.

Si simply I want to create one user control like this -- you check click this url

http://img.brothersoft.com/screenshots/softimage/m/mc3_-_mouse_click_cyber_cafe_software-271987-1268103759.jpeg[^]

Basically I am created this type of user control but I am not use to property of button or level
So Can advice what will be do and if have code of that plz share
Posted
Comments
Richard MacCutchan 18-Mar-14 7:02am    
That looks like a .NET Windows Form with a number of different controls. Plenty of samples around that will help you.
Kornfeld Eliyahu Peter 18-Mar-14 7:13am    
It seem he never heard of the magic word - Google...
Ramkrishn Mishra 18-Mar-14 11:21am    
Can you advice if have another easy way for perform my above task ?

1 solution

When you create a UserControl, you are creating a single, self contained object that you can include several times on the same form or on different forms - and you write it and use it the same way you would do for a whole form. Just like a form, the user control should have it's own properties and it's own events, which are all the outside world sees.

For example: the outside world does not need to know that your control has a button, because your control has an event which says "status changed" which the form handles. Inside your control you handle the button click event, and signal the event to the outside world:
C#
/// <summary>
/// Event to indicate Status Changed
/// </summary>
public event EventHandler StatusChanged;
/// <summary>
/// Called to signal to subscribers that Status Changed
/// </summary>
/// <param name="e"></param>
protected virtual void OnStatusChanged(EventArgs e)
    {
    EventHandler eh = StatusChanged;
    if (eh != null)
        {
        eh(this, e);
        }
    }

private void myButton_Click(object sender, EventArgs e)
    {
    OnStatusChanged(new EventArgs());
    }


Similarly, your control has properties which get and set the label content, the button colour, and so forth and the outside world interfaces with your control via those. When the outside world handles the event, it gets and sets the properties appropriately.

This way, you can safely change the internals of your control, and the outside world doesn't even have to know!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900