7 Replies - 1979 Views - Last Post: 31 May 2012 - 08:59 AM Rate Topic: -----

#1 princess18  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 07-December 09

How to put the focus on the last character in the textbox?

Posted 30 May 2012 - 07:49 PM

 

Private Sub txtOPass_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtOPass.KeyUp

        txtOPass.Text = Replace(txtOPass.Text, Mid(txtOPass.Text, Len(txtOPass.Text), 1), "*", 1, 1)

    End Sub




Good day! My aim is to replace the character inputted by the user with "*" everytime there is an keyup event. I already solved that with the code above. My problem now is that, I can't continuously input the characters in the textbox because the focus of the cursor always go in the first character. I already tried passwordchar but that's not the kind of output I want to see. I only want to see the latest inputted character change to "*". How can I put the focus on the last character? Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: How to put the focus on the last character in the textbox?

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 274
  • View blog
  • Posts: 1,653
  • Joined: 26-March 09

Re: How to put the focus on the last character in the textbox?

Posted 31 May 2012 - 12:32 AM

In vb6 you would use the SelStart,SelLength and SelText properties of the text box.

It looks as though you're using Vb.Net, so I can't comment on whether the same properties are available.
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: How to put the focus on the last character in the textbox?

Posted 31 May 2012 - 08:35 AM

To move the cursor to the end in VB.Net you can use
TextBox1.Selectionstart = TextBox1.TextLength


Of course for what it appears you're attempting, why not just set the TextBox's PasswordChar property to *? This will replace anything you type with the *

There's also the ever popular property UseSystemPasswordChar that when set to True will place the small filled circle in place of what the user types and will display according to the visual styles set by the system.

Both of these options require no code, and keeps the string intact.

You code would replace the string password with ******* and you will have no way of knowing what the user actually entered.
Was This Post Helpful? 1
  • +
  • -

#4 princess18  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 07-December 09

Re: How to put the focus on the last character in the textbox?

Posted 31 May 2012 - 08:49 AM

I already used passwordchar before. However, that is not the output i want to see. I want to see the character change to "*" as I type it. From a character, to "*" when the keyup event initializes.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: How to put the focus on the last character in the textbox?

Posted 31 May 2012 - 08:51 AM

OK, well the selectionstart set to the textlength will get you to the end.

I'm sure you're storing the characters somewhere so you know the value of that textbox's string later on anyway right?

This post has been edited by CharlieMay: 31 May 2012 - 08:52 AM

Was This Post Helpful? 0
  • +
  • -

#6 princess18  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 07-December 09

Re: How to put the focus on the last character in the textbox?

Posted 31 May 2012 - 08:52 AM

@CharlieMay, thank you so much for your help! :) It worked using

TextBox1.Selectionstart = TextBox1.TextLength
!!! Now I achieve the output I want to see. :)
Was This Post Helpful? 0
  • +
  • -

#7 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 18
  • View blog
  • Posts: 258
  • Joined: 21-May 09

Re: How to put the focus on the last character in the textbox?

Posted 31 May 2012 - 08:55 AM

the time between the key down and key up is so fast you can actually see the character change to *
for the visual effect you want to do you'll need to slow it down somehow, probably with loops.
but not only it would probably overload your program and make it slow it will also damage the string you have
Was This Post Helpful? 0
  • +
  • -

#8 princess18  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 07-December 09

Re: How to put the focus on the last character in the textbox?

Posted 31 May 2012 - 08:59 AM

@CharlieMay, in someway yes. I'm using it for security purposes. I've seen that idea in a website and liked it. :) So I'm adapting it to do my homework. Thank you again! :)

@Neku, yes I also thought of that. :) Maybe using timer for effects, but as you said, it may overload the program. Thank you anyway!

To others, thanks for the help and effort! Much appreciated! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1