其他分享
首页 > 其他分享> > Vb.Net简单绘制渐变色控件

Vb.Net简单绘制渐变色控件

作者:互联网

新建一个空白控件,控件本身什么都不用放置,大小也不需要管,粘贴代码

Imports System.Drawing
Imports System.Drawing.Image
Public Class NewLbl
    Private Color1 As Color = System.Drawing.Color.FromArgb(50, 11, 24, 42)
    Private Color2 As Color = System.Drawing.Color.FromArgb(250, 11, 24, 42)
    Private Sub frmBG_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim bmp As Bitmap = New Bitmap(10, 10) '大小随意设置的值,后面会变成控件大小
        Dim g As Graphics = e.Graphics
        Dim p1 As Point = Me.ClientRectangle.Location '渐变起点
        Dim p2 As Point = New Point(Me.ClientRectangle.Right, Me.ClientRectangle.Bottom) '渐变终点
        Using brsGradient As New System.Drawing.Drawing2D.LinearGradientBrush(p1, p2, Color1, Color2)
            g.FillRectangle(brsGradient, e.ClipRectangle)
            g.DrawImage(bmp, Me.ClientRectangle.Location)
        End Using
    End Sub
End Class

将控件添加到页面,
效果就是图中渐变的长方形。
渐变长方形

标签:Me,控件,Vb,Dim,Color,渐变色,System,Drawing
来源: https://blog.csdn.net/LemonNancy/article/details/120727957