如何在控件中设置颜色渐变的颜色

如何在控件中设置颜色渐变的颜色

本文介绍了如何在控件中设置颜色渐变的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中TabPage的颜色由颜色渐变组成,并且将有多个按钮设置TabPage的颜色.我希望单击按钮以更改TabPage的颜色时,这是下面的代码,但是单击按钮时颜色不会更改.任何人都可以分辨出问题所在,或者该怎么办?


I am creating an application in which the color of TabPage is composed of a color gradient, and there will be several buttons that set the color of TabPage. I want that when the button is clicked to change the color of TabPage, this is my code below but when I click the button color is not changed. Anyone could tell what is wrong, or how can I do this?


Dim cor1 As Color = Color.SkyBlue
  Dim cor2 As Color = Color.Lime
  Private Sub TabPageExecutarPrograma_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles TabPageExecutarPrograma.Paint
    Dim FormGraphics As Graphics = e.Graphics
    Dim GradientBrush As Brush
    GradientBrush = New LinearGradientBrush(New Point(0, 0), New Point(0, Me.Height), cor1, cor2)
    FormGraphics.FillRectangle(GradientBrush, ClientRectangle)
  End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   cor1 = Color.Blue
   cor2 = Color.Green
End Sub

推荐答案


这篇关于如何在控件中设置颜色渐变的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:52