请问谁知道这样才能将控件的背景透明?

leezhao 2002-10-19 07:36:49
我请问谁知道这样才能将控件的背景透明?
...全文
33 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
w18ily 2002-10-23
  • 打赏
  • 举报
回复
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
'Code to make the Form Transparent:

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long

Private Sub Form_Load()
Me.AutoRedraw = True
hBitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
SelectObject Me.hdc, hBitmap
Me.Refresh
End Sub
w18ily 2002-10-23
  • 打赏
  • 举报
回复
'The Code to Make the BackGround of TextBox(txtInfo) Transparent,use the CommandButton(cmdMakeTransparent):

Option Explicit
Dim DoIt As Boolean
Private Const DT_EDITCONTROL = &H2000&
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


Sub TextTrans(MyTB As TextBox)
Dim TempDC As Long
Dim Temp As String
Dim MyLoc As RECT
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
DoIt = True
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


zyl910 2002-10-19
  • 打赏
  • 举报
回复
用SetWindowRgn设置窗口(控件是一种子窗口)的显示区域


SetWindowRgn

VB声明
Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
说明
这是那些很难有人注意到的对编程者来说是个巨大的宝藏的隐含的API函数中的一个。本函数允许您改变窗口的区域。
通常所有窗口都是矩形的——窗口一旦存在就含有一个矩形区域。本函数允许您放弃该区域。这意味着您可以创建圆的、星形的窗口,也可以将它分为两个或许多部分——实际上可以是任何形状
返回值
Long,执行成功为非零值,失败为0
参数表
参数 类型及说明
hWnd Long,将设置其区域的窗口
hRgn Long,将设置的区域的句柄,一旦设置了该区域,就不能使用或修改该区域句柄,也不要删除它
bRedraw Boolean,若为TRUE,则立即重画窗口
注解
为区域指定的所有坐标都以窗口坐标(不是客户坐标)表示,它们以整个窗口(包括标题栏和边框)的左上角为起点

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧