1

i have created an windows application, i have one textbox in form1. if i run the application it works fine ,

i have set in textbox_lostfocus event-

Private Sub txtCardID_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCardID.LostFocus

    txtCardID.Focus()

End Sub

And in form deactivate event -

Private Sub frmPlay_Deactivate(sender As Object, e As EventArgs) Handles MyBase.Deactivate

    txtCardID_LostFocus(sender, e)
    Me.Activate()
End Sub

but my problem is when i click other application say-paint,or something else that becomes activate and my application loss focus

when i click my form it activate and works

i need always my form to be activated and what ever key clicked the value should enter in textbox

Hamad
  • 5,096
  • 13
  • 37
  • 65

1 Answers1

0

Read the post "How can I prevent other apps from stealing the focus?"

Or try this if not there are more than controls in your form that txtCardID:

Public Class Form1

    Private fin As Boolean

    Private Sub Form1_Deactivate(sender As Object, e As System.EventArgs) Handles Me.Deactivate

        Do
            Me.Activate()
            My.Application.DoEvents()
        Loop Until fin

    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        fin = True
    End Sub

End Class
Community
  • 1
  • 1
Aprendiendo.NET
  • 410
  • 2
  • 6
  • i used your sets of code but it restricts all application to perform its action. for eg:if i run my program it runs and i go what i need but i does'nt allow anything to work so i coudl not make my program to stop – Rekha Murugesan Nov 24 '14 at 12:22
  • what i all need is my form should always be active and also it allows other application to work – Rekha Murugesan Nov 24 '14 at 12:24
  • if you allow another application has the focus (for example with a button), then your application will be disabled and therefore the `txtCardID` textbox lose focus :( – Aprendiendo.NET Nov 24 '14 at 13:11
  • Hi Aprendiendo.NET, i made my form activate when it is in unfocused by using hotkeys,if key-g is pressed my app will get activated and i ll use it ,if i use any app like paint or anything else and i press key-g my app will get focused. so that my app get focused at same time other app also working my reference link is-http://www.dreamincode.net/forums/topic/94406-global-hotkey/ – Rekha Murugesan Nov 25 '14 at 05:21
  • any ways thank you for your valuable ideas it helped me lot.thank you once again – Rekha Murugesan Nov 25 '14 at 05:27