473,772 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting cursor position in Textbox

3 New Member
Hi, new here as a member, but have visited frequently as a guest. I'm a C# developer from Canada. I primarily work on ASP.net and Pocket PC.

I am currently in the process of writing a new mobile app with the .NET Compact framework, but have hit a snag I'm hoping someone here will know something more about than myself.

So, I have a textbox, and whenever said textbox gains focus, I'd like to set the current cursor position to a specific place. I know this can be achieved by using either of the Select() method, and SelectionStart property. As such, I've done so using the former.

Problem is that, if the textbox is clicked in to gain focus it sets the SelectionStart to the right value when it gains focus, but after my GotFocus method has completed, it changes to the position that was clicked inside the box.

In another test, I tried running the same code from my GotFocus method from elsewhere.. on formLoad specifically, and it worked exactly as expected. So, the click on the box is definitely what is throwing it off.

Any thoughts on how I can get around my problem?
May 20 '09 #1
1 5416
sypher04
3 New Member
I figured out a solution to my issue right after posting, so you can disregard my above my post. However, for anyone who may run into this problem in another project of their own. Here's my solution:

I used subclassing to provide myself with a click event for the textbox control, and then moved the code from my GotFocus event into the Click. For my purposes, having a click event is even better because I need to be able to keep the cursor locked to a position even after gaining focus.

Anyway, here's a link for on subclassing:

http://www.codeproject.com/KB/cs/Tex...bclassing.aspx
May 20 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
9062
by: Steve | last post by:
does any one know a way to determine the position of the cursor in a text box. I would like to position a list next to the current position for context commands. I am using VS.NET/C#/System.Windows.Forms.
1
3889
by: objectref | last post by:
Hi to all, we have the MousePosition property that we can get the Point of the position of the mouse cursor on the screen, but is it there a way to get the respective Point of a cursor in a TextBox ?? (relative to screen) I mean, i have a textbox that i write some text and i want to know the exact point location of the cursor at any time a character is displayed.
5
2998
by: Tina | last post by:
How is it possible to designate a textbox so that when the .aspx page is displayed the cursor is already there so the user can just start typing instead of having to click in the textbox with the mouse first? thanks, T
2
2144
by: Gene Hubert | last post by:
For a string that is being edited in a textbox, is there a way to find the position of the edit cursor in the string being edited? For example, it would be 0 or 1 at the beginning of a string and go up by one each time the right arrow key was pressed. Thanks Much, Gene in NC
22
4546
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't that difficult, but to find the next line is more difficult. For exemple: if my cursor is on line 200, it has to start searching on line 201, and not on line 1. Anybody has any ideas?
4
6259
by: Neil Robbins | last post by:
Could anyone suggest a way in which I could find the position of the cursor within a textbox. I want to evaluate every keypress made within the textbox in order to validate it but in order to do this I need to know where the cursor is when the key is pressed. So far I can't see how I could do this. Any help would be very much appreciated, Neil R.
0
1838
by: Oenone | last post by:
I would like to set the caret position in a (single-line) textbox to a position based on the number of pixels from the left of the control. For example, I want the caret to be positioned 50 pixels from the left (or as near to there as possible based on the characters in the control). I basically have the position in which the user has positioned the mouse cursor within the textbox, and want to react as if they had actually clicked it....
4
64888
by: Brandon McCombs | last post by:
Does anyone know of an easy way to set the position of the cursor in a TextBox? If I set text in the box that is longer than the length of the TextBox the position of the cursor is at the very end of the line and a user would have to use the arrow keys to move it back to the beginning of the line of text. I'd prefer to set the cursor position automatically to just before the first character of the text. thanks
6
1380
by: yasirkhan | last post by:
Hi, i am new in .net, and i am confused how to set cursor position in textbox. I have made an application of keyboard and other application of User Info. when i run my applications then the form named User info opens. in this form i have a text box, when this textbox is clicked then keyboard opens. But when i type a word from my keyboard application into the text box, then the cursor is disappeared. i want some help about this problem....
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.