Setting BorderStyle fies Enter event 
Author Message
 Setting BorderStyle fies Enter event

I'm trying to change the appearance of TextBoxes on the
fly. I want only the control with the current focus to
appear as a "standard" TextBox.  All others should blend
into the form.  I've set up event handlers for the various
TextBoxes where I set the BorderStyle and BackGround color
of the control based on whether we're Entering or Leaving
the control.  It works fine as long as the user clicks on
the controls, but when you use the tab key, things get a
little funky.  It that case setting the BorderColor of the
control seems to be refiring the Enter event.  The focus
never goes to the next control.  The code folows(I've
coded a generic handler for the Leave and Enter events,
but the behavior is exactly the same even if the code is
all in separate handlers).

Is there any way out of this?

Thanks,
Jim

    Private Sub TextBox1_Enter(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox1.Enter
        EditControl_Enter(CType(sender, TextBox))
    End Sub

    Private Sub TextBox1_Leave(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox1.Leave
        EditControl_Leave(CType(sender, TextBox))
    End Sub

    Private Sub TextBox2_Enter(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox2.Enter
        EditControl_Enter(CType(sender, TextBox))
    End Sub

    Private Sub TextBox2_Leave(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TextBox2.Leave
        EditControl_Leave(CType(sender, TextBox))
    End Sub

    Private Sub EditControl_Leave(ByVal TB As TextBox)
        Debug.WriteLine("Top of EditControl_Leave: " &
TB.Name)
        TB.BorderStyle = BorderStyle.None
        Debug.WriteLine("Middle of EditControl_Leave: " &
TB.Name)
        TB.BackColor = Me.BackColor
        Debug.WriteLine("Bottom of EditControl_Leave: " &
TB.Name)
    End Sub

    Private Sub EditControl_Enter(ByVal TB As TextBox)
        Debug.WriteLine("Top of EditControl_Enter: " &
TB.Name)
        TB.BorderStyle = BorderStyle.Fixed3D
        Debug.WriteLine("Middle of EditControl_Enter: " &
TB.Name)
        TB.BackColor = System.Drawing.Color.FromName
("Window")
        Debug.WriteLine("Bottom of EditControl_Enter: " &
TB.Name)
    End Sub



Mon, 29 Nov 2004 20:12:30 GMT  
 Setting BorderStyle fies Enter event
have a look  at code below. You can use the same procedure for all controls
by referencing their appropriate handle when the code is the same.

To overcome the problem with activeControl passing back and forth I have
removed the handle for the control then added it back after updating the
display in the Leave event. I found that it as still necessary to reference
and select the new ActiveControl in the leave event for it to work.

Private Sub Control_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter,
TextBox4.Enter
    sender.backcolor = mclrHighlight
    sender.BorderStyle = BorderStyle.Fixed3D
End Sub

Private Sub Control_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave,
TextBox4.Leave
    Dim aControl As Control = Me.ActiveControl
    Dim ctlSender As Control = sender ' couldn't add/remove handler for
sender only control?
    RemoveHandler ctlSender.Enter, AddressOf Control_Enter 'So BorderStyle
does not fire Enter event
    sender.BorderStyle = BorderStyle.FixedSingle
    sender.BackColor = mclrNormal
    AddHandler ctlSender.Enter, AddressOf Control_Enter 'Restore event
handler
    aControl.Select()
End Sub


Quote:
> I'm trying to change the appearance of TextBoxes on the
> fly. I want only the control with the current focus to
> appear as a "standard" TextBox.  All others should blend
> into the form.  I've set up event handlers for the various
> TextBoxes where I set the BorderStyle and BackGround color
> of the control based on whether we're Entering or Leaving
> the control.  It works fine as long as the user clicks on
> the controls, but when you use the tab key, things get a
> little funky.  It that case setting the BorderColor of the
> control seems to be refiring the Enter event.  The focus
> never goes to the next control.  The code folows(I've
> coded a generic handler for the Leave and Enter events,
> but the behavior is exactly the same even if the code is
> all in separate handlers).

> Is there any way out of this?

> Thanks,
> Jim

>     Private Sub TextBox1_Enter(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles TextBox1.Enter
>         EditControl_Enter(CType(sender, TextBox))
>     End Sub

>     Private Sub TextBox1_Leave(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles TextBox1.Leave
>         EditControl_Leave(CType(sender, TextBox))
>     End Sub

>     Private Sub TextBox2_Enter(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles TextBox2.Enter
>         EditControl_Enter(CType(sender, TextBox))
>     End Sub

>     Private Sub TextBox2_Leave(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles TextBox2.Leave
>         EditControl_Leave(CType(sender, TextBox))
>     End Sub

>     Private Sub EditControl_Leave(ByVal TB As TextBox)
>         Debug.WriteLine("Top of EditControl_Leave: " &
> TB.Name)
>         TB.BorderStyle = BorderStyle.None
>         Debug.WriteLine("Middle of EditControl_Leave: " &
> TB.Name)
>         TB.BackColor = Me.BackColor
>         Debug.WriteLine("Bottom of EditControl_Leave: " &
> TB.Name)
>     End Sub

>     Private Sub EditControl_Enter(ByVal TB As TextBox)
>         Debug.WriteLine("Top of EditControl_Enter: " &
> TB.Name)
>         TB.BorderStyle = BorderStyle.Fixed3D
>         Debug.WriteLine("Middle of EditControl_Enter: " &
> TB.Name)
>         TB.BackColor = System.Drawing.Color.FromName
> ("Window")
>         Debug.WriteLine("Bottom of EditControl_Enter: " &
> TB.Name)
>     End Sub



Tue, 30 Nov 2004 10:48:49 GMT  
 Setting BorderStyle fies Enter event
PS: There is no reason why you couldn't extend the textbox control and
update the Enter & leave events to action these style changes. This would
mean you could have extra properties assigned to the extented Textbox
control covering active & inactive borderstyle & colors.



Quote:
> have a look  at code below. You can use the same procedure for all
controls
> by referencing their appropriate handle when the code is the same.

> To overcome the problem with activeControl passing back and forth I have
> removed the handle for the control then added it back after updating the
> display in the Leave event. I found that it as still necessary to
reference
> and select the new ActiveControl in the leave event for it to work.

> Private Sub Control_Enter(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter,
> TextBox4.Enter
>     sender.backcolor = mclrHighlight
>     sender.BorderStyle = BorderStyle.Fixed3D
> End Sub

> Private Sub Control_Leave(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave,
> TextBox4.Leave
>     Dim aControl As Control = Me.ActiveControl
>     Dim ctlSender As Control = sender ' couldn't add/remove handler for
> sender only control?
>     RemoveHandler ctlSender.Enter, AddressOf Control_Enter 'So BorderStyle
> does not fire Enter event
>     sender.BorderStyle = BorderStyle.FixedSingle
>     sender.BackColor = mclrNormal
>     AddHandler ctlSender.Enter, AddressOf Control_Enter 'Restore event
> handler
>     aControl.Select()
> End Sub



> > I'm trying to change the appearance of TextBoxes on the
> > fly. I want only the control with the current focus to
> > appear as a "standard" TextBox.  All others should blend
> > into the form.  I've set up event handlers for the various
> > TextBoxes where I set the BorderStyle and BackGround color
> > of the control based on whether we're Entering or Leaving
> > the control.  It works fine as long as the user clicks on
> > the controls, but when you use the tab key, things get a
> > little funky.  It that case setting the BorderColor of the
> > control seems to be refiring the Enter event.  The focus
> > never goes to the next control.  The code folows(I've
> > coded a generic handler for the Leave and Enter events,
> > but the behavior is exactly the same even if the code is
> > all in separate handlers).

> > Is there any way out of this?

> > Thanks,
> > Jim

> >     Private Sub TextBox1_Enter(ByVal sender As Object,
> > ByVal e As System.EventArgs) Handles TextBox1.Enter
> >         EditControl_Enter(CType(sender, TextBox))
> >     End Sub

> >     Private Sub TextBox1_Leave(ByVal sender As Object,
> > ByVal e As System.EventArgs) Handles TextBox1.Leave
> >         EditControl_Leave(CType(sender, TextBox))
> >     End Sub

> >     Private Sub TextBox2_Enter(ByVal sender As Object,
> > ByVal e As System.EventArgs) Handles TextBox2.Enter
> >         EditControl_Enter(CType(sender, TextBox))
> >     End Sub

> >     Private Sub TextBox2_Leave(ByVal sender As Object,
> > ByVal e As System.EventArgs) Handles TextBox2.Leave
> >         EditControl_Leave(CType(sender, TextBox))
> >     End Sub

> >     Private Sub EditControl_Leave(ByVal TB As TextBox)
> >         Debug.WriteLine("Top of EditControl_Leave: " &
> > TB.Name)
> >         TB.BorderStyle = BorderStyle.None
> >         Debug.WriteLine("Middle of EditControl_Leave: " &
> > TB.Name)
> >         TB.BackColor = Me.BackColor
> >         Debug.WriteLine("Bottom of EditControl_Leave: " &
> > TB.Name)
> >     End Sub

> >     Private Sub EditControl_Enter(ByVal TB As TextBox)
> >         Debug.WriteLine("Top of EditControl_Enter: " &
> > TB.Name)
> >         TB.BorderStyle = BorderStyle.Fixed3D
> >         Debug.WriteLine("Middle of EditControl_Enter: " &
> > TB.Name)
> >         TB.BackColor = System.Drawing.Color.FromName
> > ("Window")
> >         Debug.WriteLine("Bottom of EditControl_Enter: " &
> > TB.Name)
> >     End Sub



Tue, 30 Nov 2004 10:53:34 GMT  
 Setting BorderStyle fies Enter event
Thanks! Works great! (and so obvious after seeing it)


Tue, 30 Nov 2004 19:34:26 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Any way to set ComboBox BorderStyle?

2. Setting BorderStyle property

3. Set Borderstyle and Apperance of a TextBox runtime.

4. Removing ActiveX Controls from Downloaded Program Fies Directory

5. Where can get ADO fies ?

6. ASAP: How do u set the cmdOK_Click event to have more than one event procedure

7. The Enter Event

8. Enter and Gotfocus Events

9. Enter and GotFocus events

10. catching exit/enter events of msform control in custom class

11. Enter Event for option box

12. click event when pressing enter key

 

 
Powered by phpBB® Forum Software