Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

Drawing Transparent Objects

How can I draw a semi-transparent line (Like highlighting) across a form.
I'm currently using formn.Line (x1, y1-(x2, y2), color, but it only draws lines of a solid color.
How can I make that line semi-transparent, so you can still see some of the stuff behind it?

Thanks in advance for the help!

0
Technokid
Asked:
Technokid
1 Solution
 
dr_binksCommented:
I dont think yoiu can make it semi-transparent, but you could make a it dotted like this

<line control>.BorderStyle = 3

e.g.

line1.BorderStyle = 3

hope that helps

~Binks
0
 
iHadiCommented:
Hi
you can use the BitBlt Api and use vbSrcPaint for the copy style (the last Parameter of the BitBlt)

This is how you do it

Create a project and add a picturebox (Picture1)

paste the following code in form1:

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Sub Highlight()
Dim tmpStr As String
Dim txtWidth As Long
Dim txtHight As Long

tmpStr = "This is a tryout text"

Picture1.Visible = False
' set the scalemode to pixel
Form1.ScaleMode = 3
Picture1.ScaleMode = 3
' let the control do the redrawing of itself
Form1.AutoRedraw = True
Picture1.AutoRedraw = True
' Picture1 is used for highlighting
Picture1.Top = 0
Picture1.Left = 0
Picture1.Width = Form1.ScaleWidth
Picture1.Height = Form1.ScaleHeight
' Set the color of the highlight
Picture1.BackColor = vbYellow
' Get the text dimentions
txtWidth = Form1.textWidth(tmpStr)
txtheight = Form1.TextHeight(tmpStr)
' draw a text to the form
Form1.Print tmpStr
' Do the highlight
BitBlt Form1.hDC, 0, 0, txtWidth, txtheight, Picture1.hDC, 0, 0, vbSrcAnd ' try changing this setting and see what happens
Form1.Refresh
End Sub
0
 
TechnokidAuthor Commented:
iHadi,

That works like a charm!!!

Now, 1 question -
I've modified the code so that it will "highlight" the area under the cursor, as the mouse is moved and the mouse button is pressed.  If I move the cursor at a medium or lower speed, everything looks fine. But, if I zip it across the screen, the "highlighting" is broken up.  Can you think of anything off the top of your head that would help prevent those gaps between the drawn squares?

Thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now