Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Simple text highlighting - optimization?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    21

    Resolved [RESOLVED] [2005] Simple text highlighting - optimization?

    Ok I got this to work I am just wondering if there is a way to optimize it because I want the code to be very organized so others can understand it.

    There is a textbox. The first time the user clicks any where on that textbox, all of the text is selected. The second time they click, it deselects and the cursor is placed at where he clicked. Simple, right?

    Yes but I used a bool to do this (i know it's stupid). allSelected is a public variable.

    Code:
            
        Private Sub txtUrl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUrl.Click
            If txtUrl.SelectionLength = 0 And allSelected = False Then
                txtUrl.SelectAll()
                allSelected = True
            Else
                allSelected = False
            End If
        End Sub
    Works fine but this looks so un-professional . And my mind is all jammed up right now after 5 hours of programming I can't think straight :S.

    so anyone have an idea for optimizing my code?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Simple text highlighting - optimization?

    I dont see how you could optimize that very much more..one thing I would change though, is declaring the boolean as static inside the method. No need for it to be public.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    21

    Re: [2005] Simple text highlighting - optimization?

    ty, actually declaring it as static does optimize it. I've gotten into a nasty habit of declaring everything as public (not good :/).

    ok I just wanted to see if there was any simpler way. people are going to be reading this source code so I need it to be as neat as possible because the one thing I (and I'm sure many others) hate is messy, illegible code where they have to scroll around a lot.

    as the title said, "*Simple*".

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