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

将控件添加到页面,
效果就是图中渐变的长方形。
Vb.Net简单绘制渐变色控件

上一篇:基于DotNet构件技术的企业级敏捷软件开发平台 - AgileEAS.NET - 系列目录


下一篇:vb.net 教程 8-3 数据库操作2