Results 1 to 5 of 5

Thread: [RESOLVED] Text fuzzy: Use my Brush for multiLine TextBox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Resolved [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.

    Name:  Cattura.PNG
Views: 371
Size:  27.4 KB

    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
    Attached Images Attached Images  
    Last edited by Jonney; Feb 1st, 2015 at 09:46 PM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: Text fuzzy: Use my Brush for multiLine TextBox

    I google it (multiline,brush,WM_CTLCOLOREDIT https://www.google.com/search?q=mult...&start=20&sa=N), Many coders report and complain this problem. What is solution in VB6?

    Edited: Look like vbAccelerator had solution,always respect vbAccelerator which is the most valuable Treasure for me.
    Last edited by Jonney; Feb 2nd, 2015 at 04:44 AM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: Text fuzzy: Use my Brush for multiLine TextBox

    A bit complicated. More debugs need...

  4. #4
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    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
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: Text fuzzy: Use my Brush for multiLine TextBox

    Quote Originally Posted by Tanner_H View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width