|
-
Nov 1st, 2000, 09:06 AM
#1
Thread Starter
Junior Member
I want to paint the from background in sevrel
colors and ...
I dont know how ...
ANy OnE KNoW ?
KraMba

-
Nov 1st, 2000, 09:26 AM
#2
Fanatic Member
How about this:
Code:
'//IT WILL CREATE GRADIENT
'//Set Form's AutoRedraw property to True
Option Explicit
Private Const PLANES = 14 ' Number of planes
Private Const BITSPIXEL = 12 ' Number of bits per pixel
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateSolidBrush Lib "gdi32" _
(ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function FillRect Lib "user32" _
(ByVal hDC As Long, lpRect As RECT, _
ByVal hBrush As Long) As Long
Dim fadeStyle As Integer
Private Sub FadeForm(frmIn As Form, fadeStyle As Integer)
'fadeStyle = 0 produces diagonal gradient
'fadeStyle = 1 produces vertical gradient
'fadeStyle = 2 produces horizontal gradient
'any other value produces solid medium-blue background
Static ColorBits As Long
Static RgnCnt As Integer
Dim NbrPlanes As Long
Dim BitsPerPixel As Long
Dim AreaHeight As Long
Dim AreaWidth As Long
Dim BlueLevel As Long
Dim prevScaleMode As Integer
Dim IntervalY As Long
Dim IntervalX As Long
Dim i As Integer
Dim r As Long
Dim ColorVal As Long
Dim FillArea As RECT
Dim hBrush As Long
'init code - performed only on the first pass through this routine.
If ColorBits = 0 Then
'determine number of color bits supported.
BitsPerPixel = GetDeviceCaps(frmIn.hDC, BITSPIXEL)
NbrPlanes = GetDeviceCaps(frmIn.hDC, PLANES)
ColorBits = (BitsPerPixel * NbrPlanes)
'Calculate the number of regions that the screen will be divided o.
'This is optimized for the current display's color depth. Why waste
'time rendering 256 shades if you can only discern 32 or 64 of them?
Select Case ColorBits
Case 32: RgnCnt = 256 '16M colors: 8 bits for blue
Case 24: RgnCnt = 256 '16M colors: 8 bits for blue
Case 16: RgnCnt = 256 '64K colors: 5 bits for blue
Case 15: RgnCnt = 32 '32K colors: 5 bits for blue
Case 8: RgnCnt = 64 '256 colors: 64 dithered blues
Case 4: RgnCnt = 64 '16 colors : 64 dithered blues
Case Else: ColorBits = 4
RgnCnt = 64 '16 colors assumed: 64 dithered blues
End Select
End If 'if solid then set and bail out
If fadeStyle = 3 Then
frmIn.BackColor = &H7F0000 ' med blue
Exit Sub
End If
prevScaleMode = frmIn.ScaleMode 'save the current scalemode
frmIn.ScaleMode = 3 'set to pixel
AreaHeight = frmIn.ScaleHeight 'calculate sizes
AreaWidth = frmIn.ScaleWidth
frmIn.ScaleMode = prevScaleMode 'reset to saved value
ColorVal = 256 / RgnCnt 'color diff between regions
IntervalY = AreaHeight / RgnCnt '# vert pixels per region
IntervalX = AreaWidth / RgnCnt '# horz pixels per region
'fill the client area from bottom/right
'to top/left except for top/left region
FillArea.Left = 0
FillArea.Top = 0
FillArea.Right = AreaWidth
FillArea.Bottom = AreaHeight
BlueLevel = 0
For i = 0 To RgnCnt - 1
'create a brush of the appropriate blue colour
hBrush = CreateSolidBrush(RGB(0, 0, BlueLevel))
If fadeStyle = 0 Then 'diagonal gradient
FillArea.Top = FillArea.Bottom - IntervalY
FillArea.Left = 0
r = FillRect(frmIn.hDC, FillArea, hBrush)
FillArea.Top = 0
FillArea.Left = FillArea.Right - IntervalX
r = FillRect(frmIn.hDC, FillArea, hBrush)
FillArea.Bottom = FillArea.Bottom - IntervalY
FillArea.Right = FillArea.Right - IntervalX
ElseIf fadeStyle = 1 Then 'horizontal gradient
FillArea.Top = FillArea.Bottom - IntervalY
r = FillRect(frmIn.hDC, FillArea, hBrush)
FillArea.Bottom = FillArea.Bottom - IntervalY
Else
'vertical gradient
FillArea.Left = FillArea.Right - IntervalX
r = FillRect(frmIn.hDC, FillArea, hBrush)
FillArea.Right = FillArea.Right - IntervalX
End If
'done with that brush, so delete
r = DeleteObject(hBrush)
'increment the value by the appropriate
'steps for the display colour depth
BlueLevel = BlueLevel + ColorVal
Next 'Fill any the remaining top/left holes of the client area with solid blue
FillArea.Top = 0
FillArea.Left = 0
hBrush = CreateSolidBrush(RGB(0, 0, 255))
r = FillRect(frmIn.hDC, FillArea, hBrush)
r = DeleteObject(hBrush)
Me.Refresh
End Sub
'Add this code to the form's resize procedure:
Private Sub Form_Resize()
If WindowState <> 1 Then
FadeForm Me, fadeStyle
End If
End Sub
'Add this code to the form's load procedure:
Private Sub Form_Load()
fadeStyle = 0
'mnuStyle(fadeStyle).Checked = True
End Sub
Only two colors, but it's better than one
-
Nov 1st, 2000, 09:26 AM
#3
Fanatic Member
You could use Shapes...
Cheers,
Paul.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Nov 1st, 2000, 09:39 AM
#4
_______
<?>
It can be done this way.
Add an image box stretch set to true
left to 0 and top to 0
height = form.height width = form.width
(in resize as well make sure it stays with the form)
Add a 3 color gif to the image box.
All your other controls will sit on the image.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|