Hi dear friends I want to make a semi-transparent rectangle over image box. I googled I found it but it was for VB.Net (http://www.vbforums.com/showthread.p...over-image-box ) how can I do it in VB 6.0 click the above link to see the code (vb.net)
Re: Draw a semi transparent rectangle over image box
Well it isn't clear exactly what you want to accomplish. The .Net thread seems chaotic to me so I'm not sure what they were trying to do or whether or not it might be what you want to do.
But there aren't any operations built into VB6 to do this so you have to use GDI calls, GDI+ calls, or a wrapper library for one of those APIs, or some 3rd party thing that does it some other way.
I have a class that wraps a lot of GDI operations and extending it to call AlphaBlend was pretty easy. It compiles down quite small, but you can also chop out the things it has that you don't need in your program.
Taking a stab at the problem I came up with:
Code:
Option Explicit
Private Sub mnuDoit_Click()
Dim AlphaPicture As StdPicture
Dim TextRECT As RECT
With New Drawing
.Clear .ARound(Image1.Picture.Width * .PxPerHmX), _
.ARound(Image1.Picture.Height * .PxPerHmY), _
vbBlue 'We'll "gray it" with vbBlue.
.ForeColor = vbWhite
With .Font
.Name = "Comic Sans MS"
.Size = 28
End With
TextRECT.Right = .Width
TextRECT.Bottom = .Height
.DrawText "Grayed out!", TextRECT, vbCenter, TRANSPARENT, True, valignMiddle
Set AlphaPicture = .Picture
Set .Picture = Image1.Picture
.PaintPicture AlphaPicture, Alpha:=64 'Mostly transparent.
Set Image1.Picture = .Picture
End With
End Sub
Plopping text on it was just an embellishment.
You can also just pull out the API calls and plop them inline within your Form too of course.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Re: Draw a semi transparent rectangle over image box
Well you could combine that with a new feature introduced in Windows 8 and accomplish it pretty easily.
Here I have a Visible = False blue PictureBox that I set to a layered window with Alpha at 64 positioned on top of the Image control.
The "Do it" operation merely assigns Visible = True:
Code:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" ( _
ByVal hWnd As Long, _
ByVal crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_EXSTYLE = -20
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1&
Private Const LWA_ALPHA = &H2&
Private Sub Form_Load()
With Picture1
.Move Image1.Left, Image1.Top, Image1.Width, Image1.Height
SetWindowLong .hWnd, _
GWL_EXSTYLE, _
GetWindowLong(.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes .hWnd, 0, 64, LWA_ALPHA
End With
End Sub
Private Sub mnuDoit_Click()
Picture1.Visible = True
End Sub
Running in the IDE with no "Win8 aware" manifest
Running as a compiled EXE with a "Win8 aware" manifest
Sadly most people aren't paying attention to the wealth of new things we got beginning in Vista, let alone Windows 8 and beyond. More reason to kick the habit of laying back on that dogeared, long in the tooth, creaky, old Windows XP.