当前位置: 源码素材网 » VB教程 » 详情页

VB生成颜色渐变的代码

  •   时间:2019-05-28
  • 概述:颜色渐变

VB生成颜色渐变的代码:通过调整各个颜色的增量,来生成渐变色,具体代码如下:

VERSION 5.00
Begin VB.Form Form1 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "颜色的渐变"
   ClientHeight    =   1890
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3165
   LinkTopic       =   "Form1"
   ScaleHeight     =   1890
   ScaleWidth      =   3165
   StartUpPosition =   3  '窗口缺省
   Begin VB.PictureBox Picture3 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      ForeColor       =   &H80000008&
      Height          =   1575
      Left            =   2640
      ScaleHeight     =   1545
      ScaleWidth      =   345
      TabIndex        =   2
      Top             =   120
      Width           =   375
   End
   Begin VB.PictureBox Picture2 
      Appearance      =   0  'Flat
      BackColor       =   &H00000000&
      ForeColor       =   &H80000008&
      Height          =   1575
      Left            =   120
      ScaleHeight     =   1545
      ScaleWidth      =   345
      TabIndex        =   1
      Top             =   120
      Width           =   375
   End
   Begin VB.PictureBox Picture1 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   1575
      Left            =   600
      ScaleHeight     =   103
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   127
      TabIndex        =   0
      Top             =   120
      Width           =   1935
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Form_Click()
    Dim intPicture1Width As Integer
    Dim intPicture2Red As Integer, intPicture3Red As Integer
    Dim intPicture2Green As Integer, intPicture3Green As Integer
    Dim intPicture2Blue As Integer, intPicture3Blue As Integer
    Dim intR As Integer, intG As Integer, intB As Integer
    Dim lngNewColor As Long
    Dim intI As Integer
'求Picture1的宽度,以象素为单位
    intPicture1Width = Picture1.ScaleWidth
'Picture2背景色的红色基色
    intPicture2Red = Picture2.Point(1, 1) Mod 256
'Picture2背景色的绿色基色
    intPicture2Green = (Picture2.Point(1, 1) \ 256) Mod 256
'Picture2背景色的蓝色基色
    intPicture2Blue = Picture2.Point(1, 1) \ 65536
'Picture3背景色的红色基色
    intPicture3Red = Picture3.Point(1, 1) Mod 256
'Picture3背景色的绿色基色
    intPicture3Green = (Picture3.Point(1, 1) \ 256) Mod 256
'Picture3背景色的蓝色基色
    intPicture3Blue = Picture3.Point(1, 1) \ 65536
'红色增量
    intR = (intPicture3Red - intPicture2Red) / intPicture1Width
'绿色增量
    intG = (intPicture3Green - intPicture2Green) / intPicture1Width
'蓝色增量
    intB = (intPicture3Blue - intPicture2Blue) / intPicture1Width
    For intI = 0 To intPicture1Width - 1
'渐变的颜色值
        lngNewColor = RGB(intPicture2Red + intR * intI, _
        intPicture2Green + intG * intI, intPicture2Blue + intB * intI)
'在Picture1内画线
        Picture1.Line (intI, 0)-(intI, Picture1.Height - 1), lngNewColor
    Next intI
End Sub

 

    相关内容:

    相关声明:

      若“VB生成颜色渐变的代码”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。