颜色变化的客户端状态,窗口应用程序 [英] client status on color change,window app

查看:97
本文介绍了颜色变化的客户端状态,窗口应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net中有一个client_status用户控件,

标签名为Connected,Available,Not Available,Ready,Connection Lost

我想设置状态与标签颜色的连接。

如果状态已连接,标签应显示绿色其他红色。

类似于所有其他选项...

任何人都可以给我任何想法如何在vb.net或任何代码片段中做到这一点?



提前谢谢





这里我放了一些代码片段来清除我的问题..



如何迭代所有标签,例如

lblClientStatusColor0,

lblClientStatusColor1,

lblClientStatusColor2 ...



以下代码:



Private Sub timClientStatus_Timer()

如果gIsTerminating = False那么

Dim i As Integer

For i = 0 to gMaxClientSystem - 1

''客户状态

选择Case gClientStatus(i)

Case Is = ClientStatus.NotAvailable

SetStatusNotAvailable(i)''''---下面定义的子程序

Case Is = ClientStatus.Available

SetStatusAvailable(i )

Case Is = ClientStatus.Connected

SetStatusConnected(i)

Case Is = ClientStatus.ConnectionLost

SetStatusConnectionLost (i)

Case Is = ClientStatus.Ready

SetStatusReady(i)

Case Is = ClientStatus.TLError

SetStatusTLError(i)



结束选择



''''频道设置状态

lblChannelSetupStatus(i).Caption = gChannelSetupStatus(i)



''''Env status

lblEnvString(i).Caption = gEnvStatus(i)



下一个我

结束如果



结束子



私有子SetStatusNotAvailable(vClientNr为整数)



''''----更改用户界面

lblClientStatusColor0 .BackColor = Color.White

lblClientStatus0.Text =Not Available'''''(vClientNr).Caption =可用

lblClientStatus0.Enabl ed = False

chk_ClientSelection0.Enabled = False



lblChannelSetupStatusColor0.BackColor = Color.White

lblChannelSetupStatus0.BackColor = Color.White

lblChannelSetupStatus0.Enabled = False

lblEnvString0.BackColor = Color.White

lblEnvString0.Enabled = False



结束Sub

I have a client_status user control in vb.net,
with labels named Connected,Available,Not Available,Ready,Connection Lost
I want to set status of connection with color of lable.
If status is connected ,label should show green else red color.
similarly for all other options...
Can anyone please give me any Idea how to do this in vb.net or any code snippet ?

Thanks in advance


here I am putting some code snippet to get my que clear..

How can I iterate through all the labels, for e.g.
lblClientStatusColor0,
lblClientStatusColor1,
lblClientStatusColor2...

Code Below:

Private Sub timClientStatus_Timer()
If gIsTerminating = False Then
Dim i As Integer
For i = 0 To gMaxClientSystem - 1
''Client status
Select Case gClientStatus(i)
Case Is = ClientStatus.NotAvailable
SetStatusNotAvailable(i)''''--- Subroutine defined below
Case Is = ClientStatus.Available
SetStatusAvailable(i)
Case Is = ClientStatus.Connected
SetStatusConnected(i)
Case Is = ClientStatus.ConnectionLost
SetStatusConnectionLost(i)
Case Is = ClientStatus.Ready
SetStatusReady(i)
Case Is = ClientStatus.TLError
SetStatusTLError(i)

End Select

''''Channel setup status
lblChannelSetupStatus(i).Caption = gChannelSetupStatus(i)

''''Env status
lblEnvString(i).Caption = gEnvStatus(i)

Next i
End If

End Sub

Private Sub SetStatusNotAvailable(vClientNr As Integer)

''''---- Change UI
lblClientStatusColor0.BackColor = Color.White
lblClientStatus0.Text = "Not Available" ''''(vClientNr).Caption = Available
lblClientStatus0.Enabled = False
chk_ClientSelection0.Enabled = False

lblChannelSetupStatusColor0.BackColor = Color.White
lblChannelSetupStatus0.BackColor = Color.White
lblChannelSetupStatus0.Enabled = False
lblEnvString0.BackColor = Color.White
lblEnvString0.Enabled = False

End Sub

推荐答案

你好,



存在解决这个问题之王的两种方法:

A)改变整个自定义控件的背景颜色(非常简单)

B)如果你真的只需要改变颜色标签,遍历Controls集合并更改Label类型项目的背景颜色



解决方案A

Hello,

There exists two approaches to that king of problem:
A) Change the backcolor of the whole custom control (very easy)
B) If you really need to change only the color of the labels, iterate through the Controls collection and change the backcolor of the items of type Label

Solution A
Me.BackColor = aColor





然后把那行代码在每个SetStatus方法中用正确的颜色结构替换aColor。



解决方案B



Then put that line of code in each "SetStatus" method replacing "aColor" with the correct Color structure.

Solution B

Private Sub SetLabelColor(aColor As Color)
    Dim aControl As Control
    For Each aControl In Me.Controls
        If TypeOf (aControl) Is Label Then
            aControl.BackColor = aColor
        End If
    Next
End Sub



然后在每个SetStatus方法中调用该方法,将颜色作为参数传递。



解决方案B仅适用于直接持有的标签通过您的用户控件,如果它们被放置在另一个容器(例如面板)中,那么您将需要枚举该子控件Controls集合并根据您的需要更改标签颜色。



希望我的评论能为您提供帮助。


Then put a call to that method in each "SetStatus" method passing the color as a parameter.

Solution B works only for labels directly held by your user control, if they are placed inside another container (say for example a panel), then you will need to enumerate through that subcontrol "Controls" collection and change the label colors approprietally to your need.

Hope my comments will help you.


这篇关于颜色变化的客户端状态,窗口应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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