C# 将一个控件变灰并在其上绘制另一个控件
我正在使用 WinForms。我想做一个小课程,它修改控件以显示它的工作原理。
我想在按钮上绘制一个覆盖层。它应该是半透明的灰色。 之后我想在它上面绘制一个进度条(在中心)。与此类似,但使用进度条。
我怎样才能意识到这一点?我不想设置进度条的位置,只是将其绘制在另一个进度条上。
我怎么能这样做呢? 谢谢 :)
I´m using WinForms. I want to make a little class, which modifys controls to show it´s working.
I want to draw an overlay over for example a button. It should be a half-transparent gray.
After that i want to draw a ProgressBar on over it (in the center). Similar to This, except using a progress bar.
How can i realize this? I don´t want to set the position of the progressbar, just drawing it on the other one.
How could i do this?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前也做过类似的事情。
您需要使用
Button.DrawToBitmap(位图、矩形)
获取按钮的图像。然后使位图灰度(有多种算法可用为此,我已经成功使用了最后一个,尽管可能不是最初来自这个网站)。现在,我使用整个表单而不是按钮来完成此操作,但我禁用了该表单,然后用其自身的图像覆盖整个表单,进行更改,然后用进度条覆盖它(本身位于带有其他控件的面板中) 。
您可以轻松地禁用该按钮,用包含图像和其顶部的进度条的面板覆盖它。
I have done something similar before.
You need to use
Button.DrawToBitmap(Bitmap, Rectangle)
to get the image of the button. Then make the Bitmap grayscale (there are multiple algorithms available for this; I have used the last one successfully although probably not originally from this site).Now, I did this with an entire form instead of a button, but I disabled the form, and then covered the entire form with an image of itself, altered and then covered it with the progress bar (itself in a panel with other controls).
You could just as easily disable the button, cover it with a panel containing the image and the progress bar on top of it.