| 
 | 
								
									
										|  |  
										|  |  
										| | If your video display has 256 colors or less and you assign a dithered color to the BackColor property of a TextBox control, you'll find that the background color under the text inside the TextBox is displayed in a different (solid) color. 
 To work around this issue, you must trap the WM_CTLCOLOREDIT message, that the control sends to its parent form when its background is about to be redrawn, and you must explicitly set a transparent background for the control. Here's the code that does the job:
 | 
 |  Click here to copy the following block |  | 
 Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, _
 ByVal nBkMode As Long) As Long
 
 Const WM_CTLCOLOREDIT = &H133
 Const TRANSPARENT = 1
 
 Dim WithEvents FormHook As MsgHook
 Dim TextHWnd As Long
 
 Private Sub Form_Load()
 Set FormHook = New MsgHook
 FormHook.StartSubclass Me
 TextHWnd = Text1.hWnd
 End Sub
 
 Private Sub FormHook_BeforeMessage(uMsg As Long, wParam As Long, lParam As Long, _
 retValue As Long, Cancel As Boolean)
 If uMsg = WM_CTLCOLOREDIT And lParam = TextHWnd Then
 SetBkMode wParam, TRANSPARENT
 End If
 End Sub
 | 
 |  
										|  |  
										|  |  
 
	
		| Submitted By :
					Nayan Patel 
					 (Member Since : 5/26/2004 12:23:06 PM) |  
		|  |  
		| 
				 | Job Description :   
			He is the moderator of this site and  currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |  
		| View all (893) submissions by this author 
			(Birth Date : 7/14/1981 ) |  |  |