Deselect all controls

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have a textbox and a datagrid on a winform. If the user hits enter in
the text box, I need to deselect the textbox and select no other
control. Basically, how can you make it so no control on the form has
focus.

Thanks
Chris
 
Hi Chris,

You can iterate through controls collection on the form and disable all the controls based on the key press. Something like this:

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

If e.KeyCode = Keys.Enter Then

For Each c In Me.Controls

c.Enabled = False

Next

End If

End Sub

Thanks

Mona [GrapeCity]
 
Hi,
I have a textbox and a datagrid on a winform. If the user hits enter in
the text box, I need to deselect the textbox and select no other
control. Basically, how can you make it so no control on the form has
focus.

one control will just have to be focused. For scenarios like yours, I'm
using a dummy-button on the form which is located off screen resp. out of
the form's visible area. Issuing a cmdFocusDummy.focus() will then do.

Cheers,
Olaf
 
Mona said:
Hi Chris,

You can iterate through controls collection on the form and disable all
the controls based on the key press. Something like this:


Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

If e.KeyCode = Keys.Enter Then

For Each c In Me.Controls

c.Enabled = False

Next

End If

End Sub

Thanks

Mona [GrapeCity]

Chris said:
I have a textbox and a datagrid on a winform. If the user hits enter in
the text box, I need to deselect the textbox and select no other
control. Basically, how can you make it so no control on the form has
focus.

Thanks
Chris

Disabling controls won't work, that will change the appearance of the
form. thanks though.

Chris
 
Chris said:
I have a textbox and a datagrid on a winform. If the user hits enter in
the text box, I need to deselect the textbox and select no other
control. Basically, how can you make it so no control on the form has
focus.

Why? What do you want the user to do with your Form then?

Armin
 
Armin said:
Why? What do you want the user to do with your Form then?

Armin

I'm capturing function keystrokes at that point. The system will have
no mouse so it's more like a dos app than anything else.

Chris
 
Hi,

Armin said:
Why? What do you want the user to do with your Form then?

I, for one, am using that in a touchscreen-application in order to not have
i.e. the focus-rectangle be drawn around a focused command-button.

Cheers,
Olaf
 
Olaf said:
Hi,

Armin Zingler wrote:




I, for one, am using that in a touchscreen-application in order to not have
i.e. the focus-rectangle be drawn around a focused command-button.

Cheers,
Olaf

The only controlt that can hold focus on the screen is a textbox. My
issue is that I don't want the cursor to show up in the textbox.

Chris
 
Back
Top