Cannot shift focus from custom control to other control
Author |
Message |
James Won #1 / 8
|
 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 |
|
 |
VBDotNet Team [MS #2 / 8
|
 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 |
|
 |
VBDotNet Team [MS #3 / 8
|
 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 |
|
 |
James Won #4 / 8
|
 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.
|
Sat, 04 Jun 2005 12:52:22 GMT |
|
 |
VBDotNet Team [MS #5 / 8
|
 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 |
|
 |
VBDotNet Team [MS #6 / 8
|
 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 |
|
 |
James Won #7 / 8
|
 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 |
|
 |
VBDotNet Team [MS #8 / 8
|
 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 |
|
|
|