tabcontrol, custom control textbox, and backcolor

rustyd

Well-known member
Joined
Mar 5, 2003
Messages
112
I have a custom control textbox. The backcolor of the textbox is changed when it receives/loses focus.

I recently added a Color variable to use for changing the backcolor of both focus/nofocus. I set the variable to a default value:
Code:
  Public InRGB As Color = Color.FromName("Window")
  Public OutRGB As Color = Color.FromName("Window")

This is the code that changes the backcolor in the custom control:
Code:
  Public Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
    sender.BackColor = Color.FromArgb(255, InRGB)
    msSavedText = TextBox1.Text
    Try
      If IsNothing(sender.ricsformlabel) Then
        sender.RICSFormLabel.Text = ""
      End If
    Catch
    End Try
    Try
      If Me.RICSClear And Len(sender.Text) > 0 Then
        sender.SelectAll()
      End If
    Catch
    End Try
  End Sub

  Public Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave
    Try
      sender.BackColor = Color.FromArgb(255, OutRGB)
    Catch
    End Try
  End Sub

This code works fine when placed on a form. The problem I am having is when I place it on a TabControl. The first control that can receive focus on a tabpage is being changed(?) by the tab page because in the windows generated code, I see where it has set the backcolor to ...Color.FromArgb(CType(0),CType(0),CType(0)). I have three tabs, and the first textbox on each of those tabs is getting its backcolor changed in the windows generated code. It wont change to the correct color until it receives focus. Once a tab has been selected, and the textbox receives focus, the black backcolor is gone until you close and reopen the form. I know the black backcolor is compiled into the debug exe and that is why I see it when I close/reopen the form. Only happens when the textbox is placed on a tabpage.

Why is the designer changing the backcolor in design mode? How do I prevent it?
 
I resolved this by changing the windows generated code where it initialized the backcolor to Color.FromArgb(CType(0),CType(0),CType(0)) for my custom control textboxes and changed it to
mytext.backcolor = Color.FromArgb(CType(255),CType(255),CType(255)).
 
Back
Top