フォームにグラデーションを描く |
フォームの背景にグラデーションを描く (053) | |
使用例 下記コードをフォームに貼り付けて下さい。 Option Explicit 'SampleNo=053 WindowsXP VB6.0(SP5) 2002.05.12 Private Function GetRed(colorVal As Long) As Integer GetRed = colorVal Mod 256 End Function Private Function GetGreen(colorVal As Long) As Integer GetGreen = ((colorVal And &HFF00FF00) \ 256&) End Function Private Function GetBlue(colorVal As Long) As Integer GetBlue = (colorVal And &HFF0000) \ (256& * 256&) End Function Private Sub Form_Load() Form1.Move 0, 0, 6000, 5000 End Sub Private Sub Form_Paint() Dim newColor As Long Dim ipixel As Integer Dim PWidth As Integer Dim redInc As Single Dim greenInc As Single Dim blueInc As Single Dim color1 As Long Dim color2 As Long Dim startRed As Integer Dim startGreen As Integer Dim startBlue As Integer Dim endRed As Integer Dim endGreen As Integer Dim endBlue As Integer Dim lngheight As Long color1 = &HFF0000 'StartColor color2 = &HFFFFC0 'EndColor startRed = GetRed(color1) endRed = GetRed(color2) startGreen = GetGreen(color1) endGreen = GetGreen(color2) startBlue = GetBlue(color1) endBlue = GetBlue(color2) lngheight = Form1.Height PWidth = Form1.ScaleWidth If PWidth <= 0 Then Exit Sub '最小化の場合 redInc = (endRed - startRed) / PWidth greenInc = (endGreen - startGreen) / PWidth blueInc = (endBlue - startBlue) / PWidth For ipixel = 0 To PWidth - 1 newColor = RGB(startRed + redInc * ipixel, startGreen _ + greenInc * ipixel, startBlue + blueInc * ipixel) Line (ipixel, 0)-(ipixel, lngheight - 1), newColor Next End Sub StartColorとEndColorを好きな色に変更して下さい。 VBの機能だけで表示していますので少し、表示に時間がかかるのが欠点ですが でも最近のマシンは処理が早いので案外苦にならないかも? |
2002/05/12