改变滚动条颜色的ListView中的WinForms [英] Changing color of scroll bar in ListView in WinForms

查看:927
本文介绍了改变滚动条颜色的ListView中的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能改变滚动条的颜色在的ListView 控制。这是一个Windows应用程序。

Is it possible to change the color of the scroll bar in a ListView control. It is a Windows application.

请让我知道什么财产或code,我可以用它来做到这一点。

Please let me know what property or code I can use to do this.

有人可以帮助ü如何申请主题的WinForms(到整个我的应用程序) 在雅虎通/迪格等。

can someone help u how to apply theme to winforms( to whole to my application) as in yahoo messenger/digby etc.

推荐答案

简短的回答:不,这是不可能的。

的时间越长(更准确)的答案:
不幸的是,这是隔靴搔痒简单,只要设置一个属性。其原因是所使用的的ListView 控制滚动条都没有实际的滚动条控制。他们没有自己的窗口句柄,他们的绘画被管理完全由内部的的ListView 控制。当然,在的WinForms的的ListView 控件是围绕由Win32 API提供了相同的控制只是一个瘦包装。他们都没有公开任何设施的改变滚动条的颜色。

The longer (and more accurate) answer:
Unfortunately, this is nowhere near as simple as setting a property. The reason is that the scroll bars used by the ListView control are not actual scroll bar controls. They don't have their own window handles, and their drawing is managed completely internally by the ListView control. And, of course, the ListView control in WinForms is just a thin wrapper around that same control provided by the Win32 API. Neither of them expose any facility for changing the scroll bar's color.

但情节变稠。我说,的ListView 控件(注意,这也适用于的TreeView )处理绘制的滚动条本身,应当指出,不能简单地处理它油漆事件,并吸引他们自己喜欢就可以与许多其他的WinForms控件。该油漆事件对应于窗口消息 WM_PAINT ,但另一个消息( WM_NCPAINT )被发送到一个窗口时,它的非客户区需要绘制。它按理说,滚动条都被漆成收到 WM_NCPAINT 消息的时候,因为我已经说过,他们是的ListView 控制的框架。但他们不是。

But the plot thickens. I said that the ListView control (note that this also applies to the TreeView) handles drawing the scroll bars itself, which should indicate that you can't simply handle its Paint event and draw them yourself like you can with many of the other WinForms controls. The Paint event corresponds to the window message WM_PAINT, but there is another message (WM_NCPAINT) that is sent to a window when it's non-client area needs to be painted. It stands to reason that the scrollbars are painted when the WM_NCPAINT message is received, because I've said they are part of the ListView control's frame. But they're not.

再有就是毫无意义的定制过多的问题。我该尊重用户的当前主题设置应用程序的坚决拥护者。如果我有Windows配置为使用高对比度主题(或者,如果我只是无法忍受的颜色为蓝色,所以我有一个绿色的主题,而不是),我希望在我的电脑上的应用程序使用该主题,以吸引他们的UI元素。不管你设计你的滚动条的样子,但真棒看起来您的计算机上,它保证看起来像垃圾上的一个人的的计算机。如果某人是你的用户,哎呀呀。应用程序的少数几个使用自定义主题做的很多的测试,并且仍无法从遇到的问题使他们。

Then there's the issue of pointlessly excessive customization. I'm a strong advocate for applications that respect the user's current theme settings. If I have Windows configured to use a high contrast theme (or if I just can't stand the color blue, so I have a green theme instead), I expect the applications on my computer to draw their UI elements using that theme. Whatever you design your scroll bar to look like, however awesome it looks on your computer, it's guaranteed to look like garbage on someone's computer. If that someone is one of your users, oops. The handful of applications that use custom themes do a lot of testing and that still doesn't keep them from experiencing problems.

您的也许的能够钩滚动条本身不知何故,但是这更可能出了问题,因为它们是在内核模式部分执行。事实上,我听说的 WindowBlinds的声称挂钩滚动条的作者是最困难的事情,他们不得不做。他们当然不会分享他们的任何招数。

You might be able to hook the scroll bars themselves somehow, but that's more than likely out of the question, as they are implemented partially in kernel mode. In fact, I've heard that the authors of WindowBlinds claimed hooking scroll bars was the most difficult thing they had to do. And they're certainly not sharing any of their tricks.

这似乎真的有希望的唯一的事情是詹姆斯·布朗的自定义滚动条图书馆,但它的C写的。你对你自己的移植到C#。和往常一样用这种东西,它不会是没有它的问题。阅读注释显示相当多的人有各种问题。如果你不知道的Win32 API pretty的好,你可能不会是能够解决任何错误这可能引入到应用程序中。

The only thing that really seems hopeful is James Brown's Custom Scrollbar Library, but it's written in C. You're on your own porting that to C#. And as usual with this kind of thing, it's not going to be without it's problems. Reading the comments shows quite a few people with various issues. If you don't know the Win32 API pretty well, you're probably not going to be able to fix any bugs this potentially introduces into your application.

还有一个原因就这个问题谷歌搜索几乎完​​全揭示悬而未决的问题。对于它的价值,这是的办法的WPF中更容易。

There's a reason a Google search on this subject almost exclusively uncovers unanswered questions. For what it's worth, this is way easier in WPF.

这篇关于改变滚动条颜色的ListView中的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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