473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

going to textbox

Hi

How can I force my cursor to go to the end of the text after pushing a
button.

Using System.Windows.Forms I have something like this:
TextBox textBox;
Button button;

.....
button.Click += new System.EventHandler(myButton_Click);

protected void myButton_Click(object sender, System.EventArgs e) {
-- code to activate textBox and go to the end of the text - something
like mouse click on the end of the text.
}

thx for any answers.
linux coder

Sep 4 '06 #1
2 1678
Hi Linux coder,
How can I force my cursor to go to the end of the text after pushing a
button.
Your key to success if the TextBox's SelectionStart property, with which you
can control the caret ("cursor") position. Combined with the SelectionLength
property, you can select any piece of text inside the textbox, or none at
all.

So, try this code for instance:

private void button1_Click(object sender, EventArgs e)
{
textBox1.SelectionLength = 0;
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.Focus();
}

Hope this answers your question.

(Note though that you are changing the default Windows functionality by
doing this, which in turn might raise some complaints from the users of your
application. Then again, there are many valid reasons to do exactly what you
want to do. Use proper judgement.)

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Sep 4 '06 #2
You can achieve that using the following code snippet:

textBox.Focus();
SendKeys.Send("{END}");

--
Nand Kishore Gupta
"linuxpld" wrote:
Hi

How can I force my cursor to go to the end of the text after pushing a
button.

Using System.Windows.Forms I have something like this:
TextBox textBox;
Button button;

.....
button.Click += new System.EventHandler(myButton_Click);

protected void myButton_Click(object sender, System.EventArgs e) {
-- code to activate textBox and go to the end of the text - something
like mouse click on the end of the text.
}

thx for any answers.
linux coder

Sep 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: M O J O | last post by:
Hi, I have a TextBox on my form. I capture the KeyDown event and examines the e.KeyValue - that is, I examine it like this: dim chr = chr(KeyValue). This seams to work ok .... well almost....
6
by: Maziar Aflatoun | last post by:
Hi, I have a little application that reads a text file line-by-line and processes each line depending on the CVS values. Now I want to change my program to capture this from a textbox. How do...
2
by: PromisedOyster | last post by:
How do I programmatically set the caret position to the end of a Windows edit box control? I was looking at using SendKeys but is there a better way?
0
by: Thomas Scheiderich | last post by:
I have a screen that just takes a phone book entry. In the Cell Phone question, it checks to see if the field has changed. If the field is no, it disables the textbox and greys out the label. If...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
0
by: MikeY | last post by:
Hi everyone, I posted a question very early today, but maybe I wasn't articulate enough. Hopefully this will illicit a response I've created a windows form and a User Control. This is a...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
15
by: Doogie | last post by:
I have a .net app that a user currently enters a number in a text box, hits a button and a data call is executed. She wants the ability to enter in multiple numbers (up to 100). So to make...
3
by: NDayave | last post by:
How do, I have a form with a number of textboxes that hide and unhide depending on a number or Laps of a Race. Currently I have this code to make them hide and unhide: Dim LapBox as String ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.