Results 1 to 22 of 22

Thread: Focus

  1. #1

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171

    Focus

    How do you give an object focus? I found this in MSDN, but it didn't work:

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.     TextBox1.Focus()
    4.  
    5. End Sub


    Thanks in advance,
    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Private Sub frmTimeCompare_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    2.         Secondtxt.Focus()
    3.     End Sub



    I tried many ways but I only got this way work.
    It's in the "Activated Event" of the form
    Last edited by Pirate; Nov 1st, 2002 at 05:46 PM.

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    well, the problem with that is that the activate event wont only fire at form_load I guess you should declare a boolean variable like this so that it would only happen once, otherwise everytime your form gets activated, your focus will move to textbox1

    VB Code:
    1. Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    2.         Static firstActivate As Boolean = False
    3.         If Not firstActivate Then
    4.             TextBox1.Focus()
    5.             firstActivate = False
    6.         End If
    7.     End Sub
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Forgot that there is a big difference btw. Load and Activated
    I was about to say that Mr.P.lol

  5. #5

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Thanks for the help, guys. Unfortunately, it didn't work. The code you posted, MrPolite, is the same as follows, correct?

    VB Code:
    1. Static firstActivate As Boolean = False
    2.  
    3. If firstActivate = True Then
    4.     TextBox1.Focus()
    5.     firstActivate = False
    6. End If

    This requires the user to unselect, and then reselect the form, and every time they do so, it gives focus back to the text box.
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Fat_N_Furry
    Thanks for the help, guys. Unfortunately, it didn't work. The code you posted, MrPolite, is the same as follows, correct?

    VB Code:
    1. Static firstActivate As Boolean = False
    2.  
    3. If firstActivate = True Then
    4.     TextBox1.Focus()
    5.     firstActivate = False
    6. End If

    This requires the user to unselect, and then reselect the form, and every time they do so, it gives focus back to the text box.
    well you have to change your code to if firstActive = false, otherwise it will never run

    The code I wrote ^ would select the textbox only the first time the form is activated (when it's loaded). So I thought that's what you want, isnt it? did you try my code? that works

    If you put that code in form_activate, it will select TextBox1 when the form is loaded and it would aviod doing the same thing if the form gets activated again.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Once it didn't work when I typed it in, I copied and pasted it in, and it still didn't work. Here's my current code:

    VB Code:
    1. Private Sub frmTagger_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    2.  
    3.     Static firstActivate As Boolean = False
    4.     If Not firstActivate Then
    5.         rtbEditor.Focus()
    6.         firstActivate = False
    7.     End If
    8.  
    9. End Sub

    It doesn't even give it focus if I just simply type

    VB Code:
    1. Private Sub frmTagger_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    2.     rtbEditor.Focus()
    3. End Sub

    So I think there might be something else wrong not having to do with the code.
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  8. #8
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Ok after trying for 15 minutes I finally found a way to do it.

    Put TextBox1.Focus() in the TabPage paint event handler that the textbox is on.
    Dont gain the world and lose your soul

  9. #9
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    tabpage was for another thread
    btw puting code in paint event wouldnt be good. If the user switches to another program and then switches back to your app, it will cause a paint event to fire, which will then cause the focus to move! (ouch)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Thought it was the same thread , anyway off to watch SpiderMan.
    Dont gain the world and lose your soul

  11. #11

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Originally posted by DevGrp
    ...anyway off to watch SpiderMan.
    LOL my stupid family is going to watch that possibly tonight on DVD for the second time. I almost *never* watch a movie twice, because I know what's going to happen - good guys win, bad guys die or are put in prison for life, and have an evil twinkle in their eye at the end of the movie, forshadowing the sequel where they escape and wreak havoc. My SISTER, however, will watch a movie 10-15 times, literally! I swear her brain is a big gooey mush. And then there's my brother, which I will not discuss in public.

    Anyway, now that I've given you information about my family that you probably didn't want to know, back to the topic of focus. Does anybody know what's wrong with it?


    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  12. #12
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Fat_N_Furry
    LOL my stupid family is going to watch that possibly tonight on DVD for the second time. I almost *never* watch a movie twice, because I know what's going to happen - good guys win, bad guys die or are put in prison for life, and have an evil twinkle in their eye at the end of the movie, forshadowing the sequel where they escape and wreak havoc. My SISTER, however, will watch a movie 10-15 times, literally! I swear her brain is a big gooey mush. And then there's my brother, which I will not discuss in public.

    Anyway, now that I've given you information about my family that you probably didn't want to know, back to the topic of focus. Does anybody know what's wrong with it?


    Furry
    LOL

    umm you wanna upload a part of your project? maybe someone can fix it?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  13. #13

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Sure! Actually, I'll upload all of it!
    Attached Files Attached Files
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  14. #14
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    hi
    that code just need a slight change and it works perfectly.

    Private Sub frmTagger_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

    Static firstActivate As Boolean = False
    If Not firstActivate Then
    rtbEditor.Focus()

    firstActivate = true ' change this line

    End If

    End Sub
    dd
    when in doubt, win the trick

  15. #15
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    hi
    that code just need a slight change and it works perfectly.

    Private Sub frmTagger_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

    Static firstActivate As Boolean = False
    If Not firstActivate Then
    rtbEditor.Focus()

    firstActivate = true ' change this line

    End If

    End Sub
    when in doubt, win the trick

  16. #16
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    and tab page was my thred!
    when in doubt, win the trick

  17. #17
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmmmmmmmmmm!!
    why cant I set breakpoints in you app?!!!
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  18. #18

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Thanks for everyone's help. I really appreciate it. You're all going to call me a liar for saying this, but I'm going to say it anyway - it still doesn't work. Just to clarify that we're talking about doing the same thing, here, I'll restate what we're trying to do: we're trying to give the rich text box the focus when the form loads, so the users can all just start typing right away. Can anybody think of anything else that could be wrong with this form or the code we're using? Frankly, I'm starting to think I may have a virus or something...


    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  19. #19

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Ah! I found a way to do it using the load event and a timer. It's a pretty cheap little trick, but it works.

    VB Code:
    1. Private Sub frmTagger_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.     tmrTimer.Start()
    4.  
    5. End Sub
    6. ------------------------------------------------------------------------------------
    7. Private Sub tmrTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrTimer.Tick
    8.  
    9.     rtbEditor.Focus()
    10.     tmrTimer.Stop()
    11.  
    12. End Sub

    tmrTimer's interval is set to 1. It's too bad that it can't be done from the Form_Load event at this point.


    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  20. #20
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Couldn't you just set the TabIndex of the RTB to 0?
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  21. #21
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    doesnt work. Download his project... it's weird . And I also dont know why I cant set any breakpoints in his code
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  22. #22

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Very *VERY* weird.
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width