dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Same meat, different gravy

  1. #1

    Thread Starter
    Lively Member Mallard8's Avatar
    Join Date
    Feb 2018
    Location
    Wales
    Posts
    100

    Resolved [RESOLVED] Same meat, different gravy

    Relating to a previous thread about giving focus back to the form after showing a Messagebox.
    I have another event that allows the user to clear the letters from the 8 labels and start again, in case they spelt their word wrong or decide to change the word they first thought of.

    Code:
        Private Sub btnClearBlue_Click(sender As Object, e As EventArgs) Handles btnClearBlue.Click
            For i = 1 To 8
                Dim lbl = Controls($"lblBLetter{i}")
                lbl.Text = ""
            Next
    
            num = 1
            btnClearBlue.Enabled = False
            Me.Focus()
            btnClearBlue.Enabled = True
        End Sub
    This code works but I know it's not the way to do it from previous thread.
    So I tried,

    Code:
            btnClearBlue.Enabled = False
            Me.Select() 
            btnClearBlue.Enabled = True
    Code:
            Me.Select()
    Code:
           Return
    None of which did work.
    So my question is how do I correctly code it so that after the Clear Button has been pressed the user can enter their word in the now cleared labels?
    Learning is a never ending subject.

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,429

    Re: Same meat, different gravy

    I didn't quite catch the exact consent but how about trying the "focus" object? Me.Focus or Me.Activate?
    Slow as hell.

  3. #3

    Thread Starter
    Lively Member Mallard8's Avatar
    Join Date
    Feb 2018
    Location
    Wales
    Posts
    100

    Re: Same meat, different gravy

    Sapator,
    From a previous thread
    An application developer should not be calling Focus. As the documentation says, you should be calling Select.
    Learning is a never ending subject.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,984

    Re: Same meat, different gravy

    This is what the documentation says specifically:
    Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
    We've all got the same access to that documentation so you can read it for yourself rather than my having to quote it here.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,984

    Re: Same meat, different gravy

    Quote Originally Posted by sapator View Post
    I didn't quite catch the exact consent but how about trying the "focus" object? Me.Focus or Me.Activate?
    Focus, Activate and Select are all methods, not objects.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,984

    Re: Same meat, different gravy

    I'm not really sure why you need to explicitly focus the form anyway though. That code is in a Click event handler for a Button on that form. If you have just clicked that Button then surely the form it is on has focus already.

  7. #7

    Thread Starter
    Lively Member Mallard8's Avatar
    Join Date
    Feb 2018
    Location
    Wales
    Posts
    100

    Re: Same meat, different gravy

    We've all got the same access to that documentation so you can read it for yourself rather than my having to quote it here.
    This is true but it is definitely not written with the beginner in mind, I do look at the documentation and nearly always have to look elsewhere for an explanation from someone such as yourself who is experienced enough to interpret it.

    I'm not really sure why you need to explicitly focus the form anyway though. That code is in a Click event handler for a Button on that form. If you have just clicked that Button then surely the form it is on has focus already.
    That maybe, is what should happen, unfortunately it doesn't.
    There are 8 Labels on the form you type a letter on the keyboard and it appears in the first Label, same for subsequent letters, KeyPress 2 into Label 2 etc. If you spell the word wrong you click the Clear button and start again which works with,

    Code:
            btnClearBlue.Enabled = False
            Me.Focus()
            btnClearBlue.Enabled = True
    But not with anything else I try.
    Learning is a never ending subject.

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,984

    Re: Same meat, different gravy

    Quote Originally Posted by Mallard8 View Post
    This is true but it is definitely not written with the beginner in mind, I do look at the documentation and nearly always have to look elsewhere for an explanation from someone such as yourself who is experienced enough to interpret it.
    That's not really a reason not to read it. I hear the same thing from many people but I was a beginner once too so I know what it's like. The more you read the documentation, the better you get at reading it. Even when I was a relative beginner, I answered questions on here on subjects that I had no prior experience with simply by reading the documentation that the OP hadn't bothered to. I also picked up loads of information that I wasn't looking for but found useful later on, like methods and properties of the types I was investigating. In this case, I hope that you would agree that the quote I provided in post #4 is not difficult for a person of any skill level to understand, so possibly not understanding what you find obviously isn't a good reason not to look in this case.
    Quote Originally Posted by Mallard8 View Post
    That maybe, is what should happen, unfortunately it doesn't.
    There are 8 Labels on the form you type a letter on the keyboard and it appears in the first Label, same for subsequent letters, KeyPress 2 into Label 2 etc. If you spell the word wrong you click the Clear button and start again which works with,

    Code:
            btnClearBlue.Enabled = False
            Me.Focus()
            btnClearBlue.Enabled = True
    But not with anything else I try.
    I don't know what to tell you. There's nothing about clicking a Button that will make the form it's on lose focus. Unless something is broken, it must be something you're doing. The way to diagnose oddities like this is to isolate the functionality in a test project and then make changes bit by bit until it breaks.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width