TabPage颜色事件 [英] TabPage Color event

查看:130
本文介绍了TabPage颜色事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

C#当然不是我的强项,所以我感谢所有慷慨的人分享他们的知识.我正在使用Windows窗体,并且已经阅读了事件,并找到了一些有关如何修改TabControl的出色帮助,因此我可以使用一个OnDraw事件,该事件将为选项卡添加一些颜色.

每个选项卡的颜色取决于连接变量的状态:
当前(绿色)
丢失(红色)
陈旧(黄色)

OnDraw事件对于更新每个选项卡的颜色非常有效,但是只有当用户选择其他选项卡进行查看时,才会发生.

我想发生的事情是,每当连接状态更改时,每个选项卡的颜色都会更新.例如,假设Tab#1的颜色为绿色,但是连接状态变为陈旧,因此现在该选项卡需要变为黄色,但是直到用户单击其他选项卡时,它才会像这样变色并触发OnDraw事件.



所以我想弄清楚该怎么做.当正常触发OnDraw事件时(通过用户单击其他选项卡),会将"DrawItemEventArgs"参数传递到偶数处理程序中.该变量已经填充了确定单击哪个选项卡,该选项卡的边界等所需的相关数据.因此,我不确定该变量来自何处或如何以编程方式重新创建这种重新着色的调用连接变量更改时,这些选项卡.

如果需要澄清,请告诉我!
谢谢.

Hello,

C# certainly isn''t my strong suit so I appreciate all the generous folk sharing their knowledge. I''m working with a Windows Form and I''ve read up on events and have found some excellent help on how to modify a TabControl so I can have an OnDraw event that will add some coloring to the tabs.

The color of each tab is based upon the state of a connection variable:
Current (green)
Lost (red)
Stale (yellow)

The OnDraw event works excellent for updating the color of each tab, but that only occurs when the user selects a different tab to view.

What I would like to happen is for the color of each tab to be updated whenever the connection state changes. For example, let''s say Tab#1 is colored green, but then the connection state changes to stale so now the tab needs to be colored yellow but it won''t get colored like that until the user clicks on a different tab and the OnDraw event is triggered.



So I''m trying to figure out how to do that. When the OnDraw event is triggered normally (by the user clicking on a different tab) a "DrawItemEventArgs" parameter is passed into the even handler. That variable is already populated with the pertinent data needed to figure out which tab was clicked on, the boundaries of that tab and etc. So I am unsure where it came from or how I can programmatically re-create such a call to re-color the tabs whenever the connection variable changes.

Please let me know if I need to clarify anything!
Thank you.

推荐答案

我不知道如何验证连接状态,但是我想您有某种触发器可以知道何时断开连接并在那里添加线以更改颜色.
而且,当您设置颜色时,视觉样式不会改变,这就是为什么我不知道您的代码就可以假设的原因,但是这里有个提示.

更改颜色后,请使用"Invalidate();"重建图像,因此应该像这样:

I don’t know how you are verify the connection state but I suppose that you have some kind of trigger to know when the connection is lost and there you add the line to change color.
And when you set the color the visual style doesn’t change, this is why I can assume once I don’t know your code, but here is a tip.

After you change the color use the ‘Invalidate();’ to rebuild your image, so shuld be sonthing like that:

TabPageName.Invalidate();




希望对您有帮助.




Hope this help you.


这篇关于TabPage颜色事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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