Home > Software engineering >  VB RichTextBox background image
VB RichTextBox background image

Time:09-20

I would like to achieve results, add a background image to RichTextBox control, how this can be done, thank you

I was hoping to set to transparent, but I don't know how to do, or have other method

CodePudding user response:

Transparent, in fact is the background picture posted by its cover, the following are examples of pseudo transparent form, remember, to reset after the refresh,
 Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As _ 
Long, lpRECT As Long As the RECT)

Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As _
Long, lpRECT As Long As the RECT)

Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As _
Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal _
NCombineMode As Long As Long)

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long As Long)

Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As _
Long, lpPoint As Long As POINTAPI)

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As _
Long, ByVal hRgn As Long, ByVal bRedraw As Long As Boolean)

Const RGN_AND=1
Const RGN_COPY=5
Const RGN_DIFF=4
Const RGN_OR=2
Const RGN_XOR=3

Private Type POINTAPI
X As Long
Y As Long
End Type


Private Type the RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub DataSamp ()
Dim AD As the Database
Dim aserch As QueryDef
End Sub

Public Sub MakeTransparent (FRM As Form)
Dim rctClient As the RECT, rctFrame As the RECT
Dim hClient As Long, hFrame As Long

'get window rectangle
GetWindowRect FRM hWnd, rctFrame
GetClientRect FRM hWnd, rctClient

'the window rectangle coordinates into screen coordinates
Dim lpTL As POINTAPI, lpBR As POINTAPI
LpTL. X=rctFrame. Left
LpTL. Y=rctFrame. Top
LpBR. X=rctFrame. Right
LpBR. Y=rctFrame. Bottom
ScreenToClient FRM hWnd, lpTL
ScreenToClient FRM hWnd, lpBR
RctFrame. Left=lpTL. X
RctFrame. Top=lpTL. Y
RctFrame. Right=lpBR. X
RctFrame. Bottom=lpBR. Y
RctClient. Left=Abs (rctFrame. Left)
RctClient. Top=Abs (rctFrame. Top)
RctClient. Right=rctClient. Right + Abs (rctFrame. Left)
RctClient. Bottom=rctClient. Bottom + Abs (rctFrame. Top)
RctFrame. Right=rctFrame. Right + Abs (rctFrame. Left)
RctFrame. Bottom=rctFrame. Bottom + Abs (rctFrame. Top)
RctFrame. Top=0
RctFrame. Left=0


HClient=CreateRectRgn (rctClient rctClient. Left, Top, rctClient. Right, rctClient. Bottom)
HFrame=CreateRectRgn (rctFrame rctFrame. Left, Top, rctFrame. Right, rctFrame. Bottom)

CombineRgn hFrame hClient, hFrame, RGN_XOR

SetWindowRgn FRM the hWnd hFrame, True
End Sub

Private Sub Command1_Click ()
MakeTransparent Me
End Sub

CodePudding user response:

CodePudding user response:

reference 1st floor of123 response:
pseudo transparent, is, in fact, be it obscures the background picture, the following are examples of pseudo transparent form, remember, to reset after the refresh,
 Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As _ 
Long, lpRECT As Long As the RECT)

Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As _
Long, lpRECT As Long As the RECT)

Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As _
Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal _
NCombineMode As Long As Long)

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long As Long)

Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As _
Long, lpPoint As Long As POINTAPI)

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As _
Long, ByVal hRgn As Long, ByVal bRedraw As Long As Boolean)

Const RGN_AND=1
Const RGN_COPY=5
Const RGN_DIFF=4
Const RGN_OR=2
Const RGN_XOR=3

Private Type POINTAPI
X As Long
Y As Long
End Type


Private Type the RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub DataSamp ()
Dim AD As the Database
Dim aserch As QueryDef
End Sub

Public Sub MakeTransparent (FRM As Form)
Dim rctClient As the RECT, rctFrame As the RECT
Dim hClient As Long, hFrame As Long

'get window rectangle
GetWindowRect FRM hWnd, rctFrame
GetClientRect FRM hWnd, rctClient

'the window rectangle coordinates into screen coordinates
Dim lpTL As POINTAPI, lpBR As POINTAPI
LpTL. X=rctFrame. Left
LpTL. Y=rctFrame. Top
LpBR. X=rctFrame. Right
LpBR. Y=rctFrame. Bottom
ScreenToClient FRM hWnd, lpTL
ScreenToClient FRM hWnd, lpBR
RctFrame. Left=lpTL. X
RctFrame. Top=lpTL. Y
RctFrame. Right=lpBR. X
RctFrame. Bottom=lpBR. Y
RctClient. Left=Abs (rctFrame. Left)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related