[RESOLVED] Text fuzzy: Use my Brush for multiLine TextBox
For Single line TextBox or SDK TextBoxW, my customized Brush for textbox works very well. But if the textbox's MultiLine is True, the text got "fuzzy" while I am typing or scrolling.
Code:
'In Subclass Procedure,lReturn is my Brush
Case WM_CTLCOLOREDIT
If TextBoxHandle <> 0 Then
If lParam = TextBoxHandle Then
Call pvOnCtlColorEdit(wParam, lParam, lReturn)
Exit Function 'MSG_BEFORE
End If
End If
Case WM_CTLCOLORSTATIC
If TextBoxHandle <> 0 Then
If lParam = TextBoxHandle Then
Call pvOnCtlColorStatic(wParam, lParam, lReturn)
Exit Function 'MSG_BEFORE
End If
End If
Code:
Private Sub pvOnCtlColorEdit( _
ByVal wParam As Long, _
ByVal lParam As Long, _
lReturn As Long _
)
Const TRANSPARENT As Long = 1
If (lParam = TextBoxHandle) Then
Call SetTextColor(wParam, TranslateColor(UserControl.ForeColor))
Call SetBkMode(wParam, TRANSPARENT)
lReturn = m_hBackBrush
End If
End Sub
Private Sub pvOnCtlColorStatic( _
ByVal wParam As Long, _
ByVal lParam As Long, _
lReturn As Long _
)
Const TRANSPARENT As Long = 1
If (lParam = TextBoxHandle) Then
Call SetBkMode(wParam, TRANSPARENT)
lReturn = m_hBackBrush
End If
End Sub
Private Sub pvCreateBackBrush() 'Call this before TextBox Creation and Property Let BackColor of UserControl
'-- Destroy previous if any
If (m_hBackBrush) Then
Call DeleteObject(m_hBackBrush)
m_hBackBrush = 0
End If
'-- Create solid brush
m_hBackBrush = CreateSolidBrush(TranslateColor(UserControl.BackColor))
End Sub
Public Function TranslateColor(ByVal clrColor As OLE_COLOR, Optional ByRef hPalette As Long = 0) As Long
Const CLR_INVALID = -1
If OleTranslateColor(clrColor, hPalette, TranslateColor) Then
TranslateColor = CLR_INVALID
End If
End Function
Re: Text fuzzy: Use my Brush for multiLine TextBox
Hi Jonney. I didn't see it in your sample code above, but you need to subclass WM_ERASEBKGND. This message notifies you when the background of the text box (or any control) needs to be repainted. Here is equivalent C# code if you are interested: https://social.msdn.microsoft.com/Fo...=csharpgeneral
Re: Text fuzzy: Use my Brush for multiLine TextBox
Originally Posted by Tanner_H
Hi Jonney. I didn't see it in your sample code above, but you need to subclass WM_ERASEBKGND. This message notifies you when the background of the text box (or any control) needs to be repainted. Here is equivalent C# code if you are interested: https://social.msdn.microsoft.com/Fo...=csharpgeneral
From what I tested, WM_ERASEBKGND can't resolve the problem. VBAccleerator's solution is complete. But I don't have time to prove it. Will come back in months.