[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?
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.
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*". :)