Deselect all controls

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
 
M

Mona

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]
 
O

Olaf Rabbachin

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
 
C

Chris

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
 
A

Armin Zingler

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
 
C

Chris

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
 
O

Olaf Rabbachin

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
 
C

Chris

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top