Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Set Cursor Position On Right Click Of TextBox


I want to make a textbox or RTB have the following property:

When the control is right clicked the position of the cursor changes to the position at which you clicked. (That is a similar behaviour to a left click.)

Any Idea how to do this? It is a feature not uncommon in edit controls.

Darren.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Position The Cursor Int Richtextbox By Right Click
how to position the cursor of rich text box by rigt clicking at a specific location in the richtext box(ie the selstart should become at the place where the mouse was clicked) and display context menus, if any.


please help

How To Set The Cursor To A Pixel Position, And To Make It Click
Ok, Im trying to get the mouse to go to a certain spot, and it wont. I have tried this


Code:
Private Declare Function SetCursorPos Lib "User32" (ByVal X As Long, ByVal Y As Long) As Long

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call SetCursorPos(100, 200)
End Sub


When i click it, it goes to the top of the screen, and 100 pixels over from left. It does not go down 200 pixels. Why wont it go down 200? Its extremely confusing? So its basicly at the pixels (100,0) and not (100,200)

And once I get the cursor to go where I want, how do i make it click without me having to click anything? Like if i Have the cursor go over a button, and I want it to click a button?

And finaly, this one is probably hardest
Say Right when the form loads, I want it to go to a video game, and click on certain pixels, and stuff, Im confused on how I would make it click once, then move, and click again. So how would I open VB, then open a different program, and have it clicking in the video game without me having to do anything?

Position Of Cursor In Textbox
i am trying to create a simple html editor and was wondering what i would use to make it so when i would click a button and the textbox lost focus i could place text to where the cursor was originally in the textbox.

thank you.

Get Cursor Position In Textbox
how to get current cursor position while typing in textbox ?
i used api function "getcursorpos" function but it gives cursor position with respect to screen.

Cursor Position In Textbox Vs RTB
I'm trying to make an application which mimics notepad, I did a search here about cursor position on textbox but I didn't see a property of a textbox which is like the RTB richtext.cursor.position.x So would it be easier for me to make a notepad app using RTB? But I don't know if notepad just uses textbox and I want my notpad (name of my app >_<) to be as faithful as the orig.

The Cursor Position In TextBox
Hi All,

I use a TextBox control, how can I know which is the cursor position in string?
I suppose that TextBox contain “abcde” and the cursor is after “c” so the position is 4;
When I press, for example a CommandButton, I want to insert a string after the character “c” inside of string.

Thanks in advance

Cursor Position In TextBox
Here's the problem:

I am making an advanced password box like the one in Lotus notes, which as you type your password replaces each character with a random number of X's

This is all working, but I need to move the cursor to the end of the text box, as when you set the text value of a text box the cursor moves back to the beginning.

I have tried making a selection of 0 characters at the end of the box, but that won't work.


Code:
Private Sub txtInput_KeyUp(KeyCode As Integer, Shift As Integer)
Dim i
Select Case KeyCode
Case 8
'## Delete X's
'code romoved - not important!
Case Else
'## Add X's
txtInput.Text = ""
For i = 1 To Len(m_PasswordText)
txtInput.Text = txtInput.Text + "XXX"
Next i
'## CODE HERE TO PLACE CURSOR PLEASE!
End Select
End Sub

Textbox Cursor Position?
textbox cursor position???
i never needed to know this until now ...

if i wanted to put text to a textbox all i would have to do was

text1.text = "hello"

and if i ever wanted to to put a line below that i would go

text1.text = "hello" & vbcrlf & "world"

however, now i need to insert words in the textbox with a command button ... i need it to insert the text where the blinking cursor is in the textbox ...

can anyone help?

Cursor Position In A TextBox Control
Hey Guys,
I was wondering if anyone knows how to determine the cursor position within a textbox control, or if not,suggest a work around for the following scenario:

I have an MSFlexGrid that I want to allow users to edit. Obviously, a bit of programming allows one to place a text box over the active cell in the grid. This is easy, and works without incident, but I want to add a bit more functionality by allowing the user to use the up/down left/right keys from within the textbox control to move around the grid. THe catch is that I only want the left/right keys to change the grid cell if the cursor is in the first column of the text, or the last column of the text respectively. Since there is no guarantee that any text will be HighLighted, I cannot use .SelStart.

Any thoughts would be helpful,

Thanks,

Hunter

How To Detect Cursor Position In Textbox?
I have several textboxes lay-out in horisontal line. When I press left arrow key cursor goes left to the beginning of textbox and stops there, but I want to move focus to previus textbox(left) and when cursor goes to the end of textbox(right), to move focus to next textbox.
To do that I need to detect when cursor is at the beginnig or at the end of textbox. How can I do that?

Cursor Auto Position In Textbox
Hey Guys,

How do I get my cusor to automaticaly go to a specific textbox when I load a form?

*RESOLVED* Cursor Position In A Textbox
Hi,

How do i get the position of the cursor in a textbox?

Detecting Textbox Cursor Position
Hi
How do i detect if a cursor is position at the edge of a multiline textbox?


Any help or suggestion is greatly appreciated
Thank you

Cursor Textbox Auto Position
Hey Guys,

How do I get my cusor to automaticaly go to a specific textbox when I load a form?

How To Establish Cursor Position In A Textbox
Hi all,

I have various textbox's where users can input a number.
Using one as an example of my problem...

I want to limit the input of a percentage to upto 99.99.
I know I can add validation after the users entered a value but I'm trying to be a bit smarter and not allow an invalid value to be entered in the first place.
I've restricted the length of the textbox to 5 chars and I limit entries to 0-9, '.' and backspace within the KeyPress event. However this wouldn't stop a user from entering 99999. So I've also tried to anticipate what the entry value will be once the new keystroke takes effect. All works OK unless... the user enters 99.9 then moves the cursor back and enters another 9 (so the result is 999.9). My code passes this value a valid as it adds the new keystroke to the end of the existing value so anticipating the value will be 99.99.
Is there a way I can establish where the cursor position is within the textbox so I can more accurately predict what the new value will be.?

Here's my code....

CODEPrivate Sub txtCommisionValue_KeyPress(Index As Integer, KeyAscii As Integer)
    Dim sValue As String
    Dim cValue As Currency
    Dim cMaxValue As Currency
    
    'Ensure only numeric values entered...(ignore backspace)
    If KeyAscii <> 8 Then
        KeyAscii = Mask(KeyAscii, MASK_DECIMAL, txtCommisionValue(Index), False, 2)
        
        If KeyAscii > 0 Then
            If Len(Trim(txtCommisionValue(Index))) > 0 Then
                cMaxValue = 99.99
                
                'calculate new value..
                sValue = txtCommisionValue(Index) + Chr(KeyAscii)
                cValue = CCur(sValue)
                'Ensure new value is not too large..
                If cValue > cMaxValue Then
                    KeyAscii = 0
                End If
            End If
        End If
    End If

End Sub

How To Get Current Cursor Position For A Textbox?
I have to perform some text editing in a normal textbox and I faced 3 problems:
    1. I am required to restrict the length of each line in a textbox, so I will have to do wordwrap when the text reach certain length. However I have to handle both Chinese and English so I can not just adjust the width of textbox to do so. Say width of 80 English characters is not equal to width of 40 Chinese characters (double bytes). Can anyone suggest an easy way to do this?

    2. In order to solve problem 1, I have tried to insert vbCrLf whenever the text reaches 40 Chinese characters, then I found it creates other problem when performing Insert and Delete keys. Does anyone experience the similar problems?

    3. When I tried to change the text of a textbox by coding, I found the cursor jumps back to the begining of the textbox. How do I detect the original cursor position in a textbox?

Thanks a lot.

Detecting Cursor Position In Textbox
Hi friends,
this quest may bring new idea abt data entry master form developers.
say a Master form have 10 multiple text control . I have used to move to next text control by pressing enter key. but now, i want to add one more feature to each text control.
say third text control has text = "Googld" and cursor is after char "d" if user press Right Arrow Key then focus will be moved to next textbox . If Cursor Position at left of character "G" and User Press Left Arrow Key , foucus will be move to previous textbox.
Isn't will be much fater for data entry operators ???
can anybody have idea ??????

It May seem Impossible, But Possibly We don't know the way how to reach there ????

Edited by - wwwdirzala on 12/29/2004 2:18:09 AM

Setting Cursor Position In A Textbox.
I have a text box that gets the focus when a certain command button is selected. The textbox automatically places an index letter with a dash in it when this happens also. Is there a way that I can get the cursor to set at the end of the characters instead of at the beginning? I am trying to take out the chance of any user error and if the cursor starts at the beginning of the box, they may just type over it.
Does this make any sense?
Thanks

Finding The Cursor Position Within The Textbox
Hi all,
  I need ur hlp urgently. Is it possible to find out the cursor position within the TextBox using code with VB6.
If so, how?
My proble is move focus from one textbox to onther text box when the cursor is in left most ( before the first char) and the user tries to move focus to the prev text box.

This is like a IP Address text field . Where if we pressing backspace , the cursor moves until it reaches the first text box's left position.


Any kind of hlp is appreciated.

Laks of thx in adv.
Regards,
JSam

Textbox Selection And Cursor Position
Hi

When I set textbox's selection, the cursor (or caret) is always at the end of the selection. I would like it to be in the beginning (cause textbox is smaller than text in it and with "onFocus autoselect" user sees the end of the string). It is possible with selecting with mouse from the end towards the beginning, but how to do it programmatically. I've searched API, but EM_SETSEL message doesn't allow it either.

Thanks in advance

Retrieve The Current Cursor Position In A Textbox?
Hi guys, how can i retrieve the current position at which the cursor is at in the textbox so i can use it to select it with the .sellength command.

I have searched everywhere and not found anything.

Thanks.

How To Check The Position Of Cursor In A String In A Textbox
hi,

if i have a string say "elephant" in a textbox, and the cursor is between the letters "p" and "h", how do i write a code to delete the letter "p" which is to the left of the cursor (same effect when pressing the backspace button)?

or is there a way to call the built-in backspace function from VB?

thanks.

Changing Position Of Cursor In Textbox Dynamically
hi,

how can we change the position of the cursor in the textbox ????

Suppose that my textBox contains text1="ABCDEF",i want to make the position of the cursor before the letter "D" of the textbox during the onfocus even of the textbox.

is this possible......????

please help me out.....

regds,
ashay

Get The Current Cursor Position From TextBox Control
I have a TextBox control (MSForms.TextBox) and I manipulate the characters before writing in the TextBox. How can I get the actual character position where I insert the character.

With Regards,
fazek

Position Cursor Within Textbox Data With Setfocus?
Is there a way to position the cursor within a textbox?  For instance, when a user clicks the "Add" button, a textbox is auto populated with the first 9 characters of an ID; the user enters the remaining 4.  But the cursor is positioned at the left of the text in the textbox instead of the right where the user really needs to be to begin entering.

I've tried not to use a setfocus and rely on tab order but it places cursor at the left instead of the right.  

I also formatted the text box to right justify, but again the cursor is placed to the left.

Any ideas?

Thank you,
Michelle

VB.NET Custom Textbox Control Cursor Position
Hello,

I've created a custom control inherited from the Windows.Forms.Textbox control. Basically it's a textbox that pulses in color when it has the focus. It uses a bitmap (gradient) to paint the background of the textbox, therefore I have to override the method to paint the text to make it visible.

Everything works how I want it, except for the cursor position in the textbox. When I type something into the textbox (runtime), the blinking cursor doesn't position correctly. This also depends on the font(size) I use. For example: with a larger font the cursor appears 2 or 3 letters in front of where it's supposed to be and with smaller fonts it appears farther to the back than actually should be. This is only a visual problem because backspace, delete, etc. work correctly. Does anyone have a clue of which method/property to override or shadow?

This is the code I use to draw the text into the textbox:

CODEProtected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  Dim g As Graphics = e.Graphics
  g.Clear(Parent.BackColor)
  Draw(g)
End Sub

Protected Sub Draw(ByVal g As Graphics)
  DrawBackground(g)
  DrawText(g)
End Sub

Protected Sub DrawBackground(ByVal g As Graphics)
  If Focused Then
    DrawTextboxState(g, iaDefault)
  Else
    DrawTextboxState(g, iaNormal)
  End If
End Sub

Protected Sub DrawTextboxState(ByVal g As Graphics, ByVal ia As ImageAttributes)
  Dim tb As New TextureBrush(imgFill, New Rectangle(0, 0, imgFill.Width, imgFill.Height), ia)
  tb.WrapMode = WrapMode.Tile

  g.FillRectangle(tb, 0, 0, Me.Width, Me.Height)
  tb.Dispose()
End Sub

Protected Sub DrawText(ByVal g As Graphics)
  Dim layoutrect As New RectangleF(0, 0, Me.Width, Me.Height)
  Dim fmt As New StringFormat
  fmt.Alignment = StringAlignment.Near
  fmt.LineAlignment = StringAlignment.Near

  Dim textBrush As New SolidBrush(ForeColor)
  g.DrawString(Text, Font, textBrush, layoutrect, fmt)
  textBrush.Dispose()
End Sub

Setting Cursor Position In Textbox &lt;RESOLVED&gt;
I have a textbox with, lets say, 10 chars and I want to set the cursor to the lastposition when the textbox gets the focus, how would I do that?


here is an example: by default when you click on the textbox the cursor will be where the mouse cursor is, and when it gets the focus from the "tab" button the cursor will be at the begining of the textbox ("/1234567890") but I want to get the cursor to the last position ("1234567890/") automaticly.


Thanks in advance,
Zmei



Edited by - Zmei2004 on 7/14/2004 6:28:36 AM

Getting The Last 2 Characters From The Position Of The Blinking Cursor On Textbox
Hi!

Basically as my long subject line says, I am trying to make a function that gets the last 2 characters from the position of the blinking cursor on a textbox. How would I make such a function (and what would be its passing parameters)?

Btw, this is a followup to post# 51008 .

Thanks!

- John

Using Textbox.SelStart To Set Position Of Cursor At Run Time
Can anyone help plese? : )

I have a user control containing a text box.

This text box should accept a max of 8 chars.

The text box should also have a read only pair of quotes "" enclosing up to 8 chars.
I have set the MaxLength property to 10 (8 chars and a set of quotes)
Spaces are significant in this string - so thats why I think I need the quotes. " " is meaningful and is not the same as NULL.
At run time I would like the text box to display "" and the cursor to be positioned after the first quote like "|". I've set the text property to ""
My questions are -
a) - is it possible for me to make the first and second quote read only?
b) - I've tried setting the SelStart property as follows - txt1.SelStart = 1 to position the cursor after the first " but it is not working. I've put the code in the usercontrol_GotFocus and userControl_Initialise events. But the cursor goes to the end or the beginning of the text in the textbox when the control gets focus.

Any help would be much appreciaited!
Thanks,
Mairi

Return Position Of Cursor Or Highlighted Characters In Textbox?
Hi,

I've recently needed a way to tell what part of TEXT in a TEXTBOX the cursor is currently located at, and if possible if the word (or part of word) is highlighted.

In other words, if someone highlights a part of a string in a textbox, is there any way to fire an event that will return the current cursor position, and/or the number of characters highlighted?

I've tried using

Debug.Print Text1.SelStart
Debug.Print Text1.SelLength

to figure out how to grab the info.

in a variety of events, like Change(), GotFocus(), and LostFocus(), but it doesn't seem to be returning what I need.

I would assume this would only be possible through the use of an API.

-----------

Figured it out... SILLY ME!


Code:Private Sub Text3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Debug.Print Me.Text3.SelStart
    Debug.Print Me.Text3.SelLength
    Debug.Print "-mouse-"
End Sub



Regards,
Powerfinger



Edited by - powerfinger on 1/25/2005 2:56:16 AM

How To Automatically Insert Text At Cursor Position? (multiline Textbox)
I have a multiline text box. I need to insert a line of text to wherever the cursor is within the textbox without losing what is before and after the text.

I think this will require some API calls since I don't know of any VB code to do it.

Can anyone provide some insight?

Row Position, Column Position Of Cursor In RichTextBox
I am trying to create a text editor with some enhanced specific features for my application. One of these features which is a MUST is that I need to know which row and column my cursor is on at any given time. Therefore if I use the arrow keys, or click on the RichText Box, I can update the statusbar to tell me which line number (row) and character position within the line I am on.

I am not totally sold on using the rich text box, but the files can be somewhat large, and I need the text to be editable.

VB6/Blinking Cursor/Textbox/Move Cursor
Hello!

I would like to always have a blinking cursor in my textbox.

Right now I have a touchscreen with a virual keyboard. All letter commands are sent to the textbox. When I change the properties of the textbox to Arrow (i.e. mouse pointer), the blinking cursor goes away once the virtual keyboard is pressed!

Can someone explain how I can get the blinking cursor to stay at the end of the inputted text?

Also...

I would like to create arrow keys. If the user messed up the inputted text, he can move the blinking cursor left one space at a time between inputted characters to add a letter. Then a button to move the blinking cursor back to the end of the inputted text.

Would be grateful for any help and explanations. Thanks.

Cursor Position
I was making playing around with making screensavers (the best way to learn to program). I was trying to make a trail of shapes behind the mouse(the screensaver will only close with the KeyDown and Click event), but I have a small problem, I don't know how to get the shapes to make a trail. I know how to use the MoveMouse event to get the x and y coordinates of the mouse inside the form, and making one shape stay with the mouse. Does anyone know how I can do this?
I need a way to store the previous locations of the mouse, but if I use a timer, it looks jerky?

Position The Cursor?
I have a piece of code that runs on LostFocus() - but thats neither here nor there.
When I tab out, if the value is a duplicate - a message box appears telling the user, the text box is wiped clean, however the cursor moves on to the next text box (as is his want)
Can I tell the cursor to go back to the other TextBox

Getting Cursor Position
hey all-

i asked this yesterday, but this time it is different. is there a way to get the cursor position on the form, rather than the cursor position on the screen? i want this information so that i can make a crosshair with two lines. i just want the lines to be what the cursor position it. thanks

Set Cursor Position
I just want to know if it's possible to set a starting position
for the cursor!
e.g. i've got a TextBox and want the Cursor to appear first in this TextBox


Please answer me it's a part of an test !
Thanx BH

Cursor Position
ive tried to look al over for this but i cant see it anywhere.

i want the flasing cursor to appear 3 characters in from the left in a string i.e. bob|by <-non flashing cursor
anyone know how, im very interested to find out. thanks in advance, Nell

Cursor Position
I need to find the middle of a picture box and set the cursor in the middle of it when the user click's a previous picturebox.

Basically the user clicks the next arrow(picture box) and the next tab on a tabstrip is displayed. The catch is the new tab's height shortens considerably therefore the next arrow(picture box) on the new tab is higher up the screen than the last.
I wish to place the cursor on this new picture box......

I have been through the "getCursorPos & setCursorPos" with no success.

Can anyone help?

Regards Dazza.

Cursor Position
i wanna to know how i can identify the position for a cursor in a text or roch text ??

for example in Vb when i write text1. ( a list will apear at th position of last Charecter ) how i can do that ?

Cursor Position
How do u find Cirsor position in pixels... id like to move a picture based on the position of the mouse pointer
thx

Cursor Position Et. Al.
Hello all, just realized this is the first post I've posted in a few months. But I digress.

I have several problems.

1) I need to set the cursor position to a specific spot in a text box and I haven't figured out how to do that yet. Any help would be appreciated.

2) Is there a way to save an html file from a rich text box without the html code shown on the page? (i.e. I have saved a richtext box as an html file and I couldn't get the html code itself to save)

Edit:
I figured out the third one...


Thanks in advance,
MikeJ

Cursor Position
If i want to get the actual cursorposition on my screen, which code do i have to use??

Cursor Position
I am having a problem with the cursor position in a text box. I have the following code so far but i need to get the cursor under the "mat" on the second line.

Private Sub mnunew_Click()
a = InputBox("Enter work number(1-9999)")
frmmaz2.Visible = True
frmmaz2.Caption = a
frmmaz2.Text1.Text = "UNO Mat init-z" + vbCrLf + " 0"
End Sub

After running the sub, the cursor goes back to the left of the "UNO". I need it under the "Mat" to accept user input and then tab under the "Init-z". How do I do this?

Thanks

Cursor Position
Hi all,
I have a form with two comboboxes and 5 command buttons.What I want to do is if the cursor is in the two comboboxes and when I click any of the 5 buttons, I want to bring back the cursor the to combobox where it was originally before clicking any of these buttons.How can I

Thks in Advance
Dan

Cursor Position
Hi all,
Its me again. I am having two textboxes and command button. When i click the command button, I want to detect where the cursor came from either from Textbox1 and Textbox2.How can I.When I used Me.ActiveControl.Name it gave me the present control name only.How can I get the previous control name

Dana

Cursor Position
I'd like to know how to get the cursor X coordinates. I have this Image that i would like to be able to move left and right by holding down the mouse button on it and moving the mouse, but only on the X-axis. Thanks in advance.

Cursor Position
I am using SelStart to place my cursor at the end of the text in a text box control. How can I have the cursor positioned at the next line.

Cursor Position
Dear friend.

How can we get the cursor position?
As an example, we want that a listbox on the cursor position, how can we get that position?

THX....

Copyright © 2005-08 www.BigResource.com, All rights reserved