如何更改表单(渐变)运行时的颜色? [英] how to change the color of the form (gradient) runtime?
本文介绍了如何更改表单(渐变)运行时的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大师,
因为语言不好意思,
我想将表单(渐变)的颜色从低级颜色更改为高级颜色,就像进度条一样,几乎就像启动屏幕一样,显示表单然后将其隐藏,
但我不能:(
最好的祝愿和梦想...
hi masters,
excuse me because of the language,
i want to change the color of the form (gradient) for a while from low level of the color to the high , like a progress bar, almost like a splash screen, show the form & then hide it,
but i CAN''T :(
best wishes & dreams...
推荐答案
覆盖方法Form.OnPaint
.在此方法中,使用通过事件参数参数传递给您的System.Drawing.Graphics
实例,并使用其方法System.Drawing.Graphics.FillRectangle
在窗体上绘画.对于画笔,请使用渐变画笔System.Drawing.Drawing2D.LinearGradientBrush
.
请参阅:
http://msdn.microsoft.com/en-us/library/yysstebh.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. drawing.drawing2d.lineargradientbrush.aspx [ ^ ].
不要忘记布置实现System.IDisposable
的对象.做到这一点并保证即使抛出异常也会发生的最佳方法是使用using
语句,该语句的作用与try-finally块相同:
http://msdn.microsoft.com/en-us/library/system.idisposable.aspx [^ ],
http://msdn.microsoft.com/en-us/library/yh598w02%28v = vs.100%29.aspx [ ^ ].
您可能会遇到一些闪烁.您可以在表单(或其他控件)中使用双缓冲来消除它,在该表单中您可以进行自定义呈现:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx [ ^ ].
致以最良好的祝愿和唤醒……:-)
—SA
Override the methodForm.OnPaint
. In this method, use the instance ofSystem.Drawing.Graphics
passed to you via the event argument parameters, and paint on the form using its methodSystem.Drawing.Graphics.FillRectangle
. For a brush, use a gradient brushSystem.Drawing.Drawing2D.LinearGradientBrush
.
Please see:
http://msdn.microsoft.com/en-us/library/yysstebh.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.lineargradientbrush.aspx[^].
Don''t forget to dispose the objects which implementSystem.IDisposable
. The best way of doing it and guarantee that it happens even if an exception is thrown, is using theusing
statement, which acts identically to the try-finally block:
http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[^],
http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.100%29.aspx[^].
You may face some flicker. You can eliminate it using double buffering for the form (or other control) where you do your custom rendering:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx[^].
Best wishes and wake-ups… :-)
—SA
这篇关于如何更改表单(渐变)运行时的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文