|
-
May 28th, 2009, 06:12 PM
#2
Re: Tranparent color...
Here's one way:
Code:
Option Explicit
Dim DoIt As Boolean
Private Const BDR_SUNKENOUTER = &H2
Private Const BDR_RAISEDINNER = &H4
Private Const DT_EDITCONTROL = &H2000&
Private Const EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
Private Const BF_BOTTOM = &H8
Private Const BF_LEFT = &H1
Private Const BF_RIGHT = &H4
Private Const BF_TOP = &H2
Private Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
Private Const DT_LEFT = &H0
Private Const DT_TOP = &H0
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function DrawCaption Lib "user32" _
(ByVal hWnd As Long, ByVal hdc As Long, pcRect As RECT, ByVal un As Long) As Long
Private Declare Function DrawEdge Lib "user32" _
(ByVal hdc As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
Private Declare Function SetRect Lib "user32" _
(lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Sub TextTrans(MyTB As Object)
'==============================
Dim TempDC As Long
Dim Temp As String
Dim MyLoc As RECT
On Error Resume Next
Temp = MyTB.Text
MyLoc.Left = MyTB.Left
MyLoc.Top = MyTB.Top
MyLoc.Right = MyLoc.Left + MyTB.Width
MyLoc.Bottom = MyLoc.Top + MyTB.Height
'MyTB.Parent.Cls
MyTB.Parent.ForeColor = MyTB.ForeColor
Set MyTB.Parent.Font = MyTB.Font
DrawText MyTB.Parent.hdc, Temp, Len(Temp), MyLoc, DT_EDITCONTROL
TempDC = GetDC(MyTB.hWnd)
BitBlt TempDC, 0, 0, MyTB.Width, MyTB.Height, MyTB.Parent.hdc, MyTB.Left, MyTB.Top, vbSrcCopy
End Sub
Private Sub cmdMakeTransparent_Click()
TextTrans txtInfo
TextTrans RichTextBox1
TextTrans Picture1
Dim MyRect As RECT
Dim X1&, Y1&, X2&, Y2&
Dim strText As String
Me.Cls
Me.ScaleMode = vbPixels
X1 = Frame1.Left - 2
Y1 = Frame1.Top - 2
X2 = X1 + Frame1.Width + 4
Y2 = Y1 + Frame1.Height + 4
SetRect MyRect, X1, Y1, X2, Y2
'Me.ScaleMode = vbTwips
SetRect MyRect, X1, Y1, X2, Y2
DrawEdge Me.hdc, MyRect, EDGE_ETCHED, BF_RECT
strText = Frame1.Caption
SetRect MyRect, X1 + 10, Y1 - 5, X2, Y2
DrawText Me.hdc, strText, Len(strText), MyRect, DT_LEFT Or DT_TOP
TextTrans Frame1
TextTrans List1
End Sub
Private Sub Form_Activate()
txtInfo.SetFocus
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Picture1.Move X, Y
TextTrans Picture1
End Sub
Private Sub Form_Load()
'cmdMakeTransparent_Click
End Sub
Private Sub Frame1_Click()
MsgBox "hi"
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Drag vbBeginDrag
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Drag vbEndDrag
End Sub
Private Sub txtInfo_Change()
If Not DoIt Then Exit Sub
TextTrans txtInfo
End Sub
Private Sub txtInfo_KeyPress(KeyAscii As Integer)
If Not DoIt Then Exit Sub
TextTrans txtInfo
End Sub
Private Sub txtInfo_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not DoIt Then Exit Sub
TextTrans txtInfo
End Sub
The other is Alpha Blending, which is probably better. Search for it
Tags for this Thread
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
|