我想创建具有1个按钮和2个标签的用户控件, [英] I want to create user control which have 1 button and 2 labels,

查看:93
本文介绍了我想创建具有1个按钮和2个标签的用户控件,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建具有1个按钮和2个标签的用户控件,第一个按钮显示颜色并告知终端是否已连接,一个标签显示PC终端#或ID和另一个标签显示多少时间像计时器或秒表一样离开



我只想创建一个这样的用户控件 - 你点击这个url



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



基本上我创建了这种类型的用户控件,但我不习惯使用属性按钮或级别

所以可以建议将要做什么以及是否有该plz共享的代码

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

推荐答案

当您创建UserControl时,你正在创建一个单独的,自包含的对象,你可以在同一个表单或不同的表单上多次包含 - 然后你编写并使用它就像你做的那样整个表格。就像一个表单一样,用户控件应该拥有它自己的属性和它自己的事件,这些都是外界看到的。



例如:外部世界没有需要知道你的控件有一个按钮,因为你的控件有一个事件,表示表单处理的状态已更改。在您的控制范围内,您可以处理按钮点击事件,并向外界发出信号:

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:
/// <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!


这篇关于我想创建具有1个按钮和2个标签的用户控件,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆