Cannot shift focus from custom control to other control 
Author Message
 Cannot shift focus from custom control to other control

Hi all,

I've created a custom control which is composed by a
textbox and some other controls.  The textbox control is
the only editable and tab-enabled control.  My problem is
I can't press [Tab] key (neither [Shift]-[Tab]) inside
this textbox control to shift focus to next control on
parent form (the form contains this custom control and
other controls).  More worse is that neither KeyPress
event nor KeyDown can trap [Tab] key, so I can't write
code to shift focus.  Does anybody have any idea on this
issue?

Thanks for your attention and help!

Regards,
James



Fri, 03 Jun 2005 09:32:49 GMT  
 Cannot shift focus from custom control to other control
Hi James,

I need a lilltle more info on what your doing. I created a simple control
with a textbox and two buttons. I set the tabstops for the buttons to False.
When I put this control on a form with other controls, I can tab both on to
and out of the textbox on my custom control.

Craig
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Hi all,

> I've created a custom control which is composed by a
> textbox and some other controls.  The textbox control is
> the only editable and tab-enabled control.  My problem is
> I can't press [Tab] key (neither [Shift]-[Tab]) inside
> this textbox control to shift focus to next control on
> parent form (the form contains this custom control and
> other controls).  More worse is that neither KeyPress
> event nor KeyDown can trap [Tab] key, so I can't write
> code to shift focus.  Does anybody have any idea on this
> issue?

> Thanks for your attention and help!

> Regards,
> James



Sat, 04 Jun 2005 05:04:30 GMT  
 Cannot shift focus from custom control to other control
James, sorry, could you give a few more details. I've created a custom
control with a TextBox on it and have not been able to reproduce the TAB
failure that you are seeing. I've tried using regular and multi-line modes.

John
The VB .NET Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> Hi all,

> I've created a custom control which is composed by a
> textbox and some other controls.  The textbox control is
> the only editable and tab-enabled control.  My problem is
> I can't press [Tab] key (neither [Shift]-[Tab]) inside
> this textbox control to shift focus to next control on
> parent form (the form contains this custom control and
> other controls).  More worse is that neither KeyPress
> event nor KeyDown can trap [Tab] key, so I can't write
> code to shift focus.  Does anybody have any idea on this
> issue?

> Thanks for your attention and help!

> Regards,
> James



Sat, 04 Jun 2005 05:00:26 GMT  
 Cannot shift focus from custom control to other control

Hi Craig,

Thanks for your reply!  I've tried many different ways to
solve my problem but all were failed even I changed my
routine to very very simple testing code.

Attached is simple version of my custom control.  There's
only one textbox inside now.  What I want to do is:
a) When the custom control got focus, change textbox's
color.
b) When the custom control lost focus, change back
textbox's color.
c) Of course, in my real project, many other things to do
when getting focus and lossing focus.

You'll find that I've created a variable called
intEnterCounter which will be accumulated within
clsTestBox_Enter event.  In clsTestBox_Leave event, I
keep track intEnterCounter just before and after calling
Me.ActiveControl = Nothing.  The result I got is:
a) If I click other control on the parent form, the
counter is same before and after call Me.ActiveControl =
Nothing.  That means no re-entry occurs.  The color
changes as expected.
b) If I press [Tab] or [Shift]-[Tab] within my custom
control, the counter after calling Me.ActiveControl =
Nothing is greater than the counter before calling.  That
means re-entry occurs.  The color does't change and focus
is still inside my custom control.  That's exact the
problem I'm facing now.

I hope you can understand my long explaination and point
out what I've done wrong.

Thanks for your help again!

(p.s. I've posted another message before talking about
similar problem.  Eric has replied but he also need more
information.  I've also provided my source code to him.  
If possible, you may discuss with him and try to find out
the answer together.)

Regards,
James Wong

Quote:
>-----Original Message-----
>Hi James,

>I need a lilltle more info on what your doing. I created
a simple control
>with a textbox and two buttons. I set the tabstops for

the buttons to False.
Quote:
>When I put this control on a form with other controls, I
can tab both on to
>and out of the textbox on my custom control.

>Craig
>VB Team

>--
>This posting is provided "AS IS" with no warranties, and
confers no rights.

  TestBox.vb
3K Download


Sat, 04 Jun 2005 12:52:22 GMT  
 Cannot shift focus from custom control to other control
Hi James,

I believe what you need to do is use the events for the custom control
rather than the events for the textbox on the control. I created a custom
control with two buttons and a textbox (Textbox1). By adding the following
code to the custom control, I get the behavior you desire (the textbox is
aqua when it has the focus, otherwise it's normal).

    Private Sub UserControl1_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Enter
        Me.TextBox1.BackColor = System.Drawing.Color.Aqua

    End Sub

    Private Sub UserControl1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Leave
        Me.TextBox1.BackColor = System.Drawing.SystemColors.Window
    End Sub

Let me know if this helps and I'll play with what you sent to see if I can
make a more sprcific example.

Craig
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Hi Craig,

> Thanks for your reply!  I've tried many different ways to
> solve my problem but all were failed even I changed my
> routine to very very simple testing code.

> Attached is simple version of my custom control.  There's
> only one textbox inside now.  What I want to do is:
> a) When the custom control got focus, change textbox's
> color.
> b) When the custom control lost focus, change back
> textbox's color.
> c) Of course, in my real project, many other things to do
> when getting focus and lossing focus.

> You'll find that I've created a variable called
> intEnterCounter which will be accumulated within
> clsTestBox_Enter event.  In clsTestBox_Leave event, I
> keep track intEnterCounter just before and after calling
> Me.ActiveControl = Nothing.  The result I got is:
> a) If I click other control on the parent form, the
> counter is same before and after call Me.ActiveControl =
> Nothing.  That means no re-entry occurs.  The color
> changes as expected.
> b) If I press [Tab] or [Shift]-[Tab] within my custom
> control, the counter after calling Me.ActiveControl =
> Nothing is greater than the counter before calling.  That
> means re-entry occurs.  The color does't change and focus
> is still inside my custom control.  That's exact the
> problem I'm facing now.

> I hope you can understand my long explaination and point
> out what I've done wrong.

> Thanks for your help again!

> (p.s. I've posted another message before talking about
> similar problem.  Eric has replied but he also need more
> information.  I've also provided my source code to him.
> If possible, you may discuss with him and try to find out
> the answer together.)

> Regards,
> James Wong

> >-----Original Message-----
> >Hi James,

> >I need a lilltle more info on what your doing. I created
> a simple control
> >with a textbox and two buttons. I set the tabstops for
> the buttons to False.
> >When I put this control on a form with other controls, I
> can tab both on to
> >and out of the textbox on my custom control.

> >Craig
> >VB Team

> >--
> >This posting is provided "AS IS" with no warranties, and
> confers no rights.



Sun, 05 Jun 2005 04:34:23 GMT  
 Cannot shift focus from custom control to other control
Hi James,

Here's a better answer:

    Private Sub UserControl1_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Enter
        If Me.TextBox1.Focus Then
            Me.TextBox1.BackColor = System.Drawing.Color.Aqua
        End If
    End Sub

    Private Sub UserControl1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Leave
        Me.TextBox1.BackColor = System.Drawing.SystemColors.Window
    End Sub

    Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Enter
        Me.TextBox1.BackColor = System.Drawing.Color.Aqua
    End Sub

    Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Leave
        Me.TextBox1.BackColor = System.Drawing.SystemColors.Window
    End Sub

I think this will do what you want. Let me know if I'm missing something.

Craig
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Hi Craig,

> Thanks for your reply!  I've tried many different ways to
> solve my problem but all were failed even I changed my
> routine to very very simple testing code.

> Attached is simple version of my custom control.  There's
> only one textbox inside now.  What I want to do is:
> a) When the custom control got focus, change textbox's
> color.
> b) When the custom control lost focus, change back
> textbox's color.
> c) Of course, in my real project, many other things to do
> when getting focus and lossing focus.

> You'll find that I've created a variable called
> intEnterCounter which will be accumulated within
> clsTestBox_Enter event.  In clsTestBox_Leave event, I
> keep track intEnterCounter just before and after calling
> Me.ActiveControl = Nothing.  The result I got is:
> a) If I click other control on the parent form, the
> counter is same before and after call Me.ActiveControl =
> Nothing.  That means no re-entry occurs.  The color
> changes as expected.
> b) If I press [Tab] or [Shift]-[Tab] within my custom
> control, the counter after calling Me.ActiveControl =
> Nothing is greater than the counter before calling.  That
> means re-entry occurs.  The color does't change and focus
> is still inside my custom control.  That's exact the
> problem I'm facing now.

> I hope you can understand my long explaination and point
> out what I've done wrong.

> Thanks for your help again!

> (p.s. I've posted another message before talking about
> similar problem.  Eric has replied but he also need more
> information.  I've also provided my source code to him.
> If possible, you may discuss with him and try to find out
> the answer together.)

> Regards,
> James Wong

> >-----Original Message-----
> >Hi James,

> >I need a lilltle more info on what your doing. I created
> a simple control
> >with a textbox and two buttons. I set the tabstops for
> the buttons to False.
> >When I put this control on a form with other controls, I
> can tab both on to
> >and out of the textbox on my custom control.

> >Craig
> >VB Team

> >--
> >This posting is provided "AS IS" with no warranties, and
> confers no rights.



Sun, 05 Jun 2005 04:46:43 GMT  
 Cannot shift focus from custom control to other control
Hi Craig,

Thanks for your reply again!  Your solution will work in
simple case.  However, my attachment is a simplified
version of my real case.  In fact, the textbox control
inside custom control is another custom control which has
special handles when getting and losing focus.  My custom
textbox control is a mask edit control which handles like
ID number, phone numbers, ISBN, barcode, and also
calculator-style numeric digit (inserts digits from right
to left and thousand separators are added in middle
automatically).  Not only chaning colors but also other
routines should be executed everytime entering and
leaving the custom textbox control.  I implement Enter
event and Leave event in my custom textbox control.  So I
need my custom textbox control to lose focus (and execute
Leave event) once the custom container control (TestBox
in my sample) lost focus, to make sure the Enter event of
custom textbox control will be executed when the custom
container control got focus again.

Thanks for your attention and help again!

Regards,
James

Quote:
>-----Original Message-----
>Hi James,

>I believe what you need to do is use the events for the
custom control
>rather than the events for the textbox on the control. I
created a custom
>control with two buttons and a textbox (Textbox1). By

adding the following
Quote:
>code to the custom control, I get the behavior you

desire (the textbox is
Quote:
>aqua when it has the focus, otherwise it's normal).

>    Private Sub UserControl1_Enter(ByVal sender As
Object, ByVal e As
>System.EventArgs) Handles MyBase.Enter
>        Me.TextBox1.BackColor = System.Drawing.Color.Aqua

>    End Sub

>    Private Sub UserControl1_Leave(ByVal sender As
Object, ByVal e As
>System.EventArgs) Handles MyBase.Leave
>        Me.TextBox1.BackColor =

System.Drawing.SystemColors.Window
Quote:
>    End Sub

>Let me know if this helps and I'll play with what you

sent to see if I can
Quote:
>make a more sprcific example.

>Craig
>VB Team

>--
>This posting is provided "AS IS" with no warranties, and

confers no rights.


Sun, 05 Jun 2005 09:56:15 GMT  
 Cannot shift focus from custom control to other control
Hi James,

I would guess that for the kind of control you want you'll need to use a
textbox control that is derived from System.Windows.Forms.TextBox but
overrides DefWndProc so you can grab and react to the windows messages. I'll
see if I can hunt down an example.

Craig
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Hi Craig,

> Thanks for your reply again!  Your solution will work in
> simple case.  However, my attachment is a simplified
> version of my real case.  In fact, the textbox control
> inside custom control is another custom control which has
> special handles when getting and losing focus.  My custom
> textbox control is a mask edit control which handles like
> ID number, phone numbers, ISBN, barcode, and also
> calculator-style numeric digit (inserts digits from right
> to left and thousand separators are added in middle
> automatically).  Not only chaning colors but also other
> routines should be executed everytime entering and
> leaving the custom textbox control.  I implement Enter
> event and Leave event in my custom textbox control.  So I
> need my custom textbox control to lose focus (and execute
> Leave event) once the custom container control (TestBox
> in my sample) lost focus, to make sure the Enter event of
> custom textbox control will be executed when the custom
> container control got focus again.

> Thanks for your attention and help again!

> Regards,
> James

> >-----Original Message-----
> >Hi James,

> >I believe what you need to do is use the events for the
> custom control
> >rather than the events for the textbox on the control. I
> created a custom
> >control with two buttons and a textbox (Textbox1). By
> adding the following
> >code to the custom control, I get the behavior you
> desire (the textbox is
> >aqua when it has the focus, otherwise it's normal).

> >    Private Sub UserControl1_Enter(ByVal sender As
> Object, ByVal e As
> >System.EventArgs) Handles MyBase.Enter
> >        Me.TextBox1.BackColor = System.Drawing.Color.Aqua

> >    End Sub

> >    Private Sub UserControl1_Leave(ByVal sender As
> Object, ByVal e As
> >System.EventArgs) Handles MyBase.Leave
> >        Me.TextBox1.BackColor =
> System.Drawing.SystemColors.Window
> >    End Sub

> >Let me know if this helps and I'll play with what you
> sent to see if I can
> >make a more sprcific example.

> >Craig
> >VB Team

> >--
> >This posting is provided "AS IS" with no warranties, and
> confers no rights.



Mon, 06 Jun 2005 04:26:44 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Focus of constituent control inside custom control

2. How to shift focus when most controls disabled?

3. Any ways to make focus on Label control like focus in button control

4. Handling the focus in a custom control inside a datagrid cell

5. custom form control: Cannot view design view of forms that inherit this form

6. Handling the focus in a custom control inside a datagrid cell

7. Cannot load (or register) custom control ...

8. Cannot load (or register) custom control ...

9. which control on focus has focus??

10. more mouse control, and keeping the focus on ONE control

11. Set focus to a control in an array of controls

12. Cancel a control's lostfocus before another control gets the focus

 

 
Powered by phpBB® Forum Software