473,322 Members | 1,614 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,322 software developers and data experts.

Insert text into textbox at caret?

Hi there,

I'm designing a winforms app in VB.NET 2.0 and have a textbox control and
also some toolbar buttons. I want to have it such that when the user clicks a
toolbar button, some predefined text - such as the date - is inserted into
the textbox at the point where the caret is. (It's assumed that the user will
be typing and then click the toolbar button.) From my research the textbox
control doesn't seem to support any method of querying the position of the
cursor. I've found documentation on pulling in the function "GetCaretPos"
from user32.dll and using that, but those examples seem to return coordinates
of the caret and not a linear position in the text. Is there a good way
anyone can think of to achieve this?

Thanks...

-Ben
Jun 26 '06 #1
4 19323
Look at the 'SelectionStart' property.
--
Terry
"Ben R." wrote:
Hi there,

I'm designing a winforms app in VB.NET 2.0 and have a textbox control and
also some toolbar buttons. I want to have it such that when the user clicks a
toolbar button, some predefined text - such as the date - is inserted into
the textbox at the point where the caret is. (It's assumed that the user will
be typing and then click the toolbar button.) From my research the textbox
control doesn't seem to support any method of querying the position of the
cursor. I've found documentation on pulling in the function "GetCaretPos"
from user32.dll and using that, but those examples seem to return coordinates
of the caret and not a linear position in the text. Is there a good way
anyone can think of to achieve this?

Thanks...

-Ben

Jun 26 '06 #2
Thanks!

textBox1.Text = textBox1.Text.Insert(textBox1.SelectionStart, "Test");

worked beautifully...

-Ben

"Terry" wrote:
Look at the 'SelectionStart' property.
--
Terry
"Ben R." wrote:
Hi there,

I'm designing a winforms app in VB.NET 2.0 and have a textbox control and
also some toolbar buttons. I want to have it such that when the user clicks a
toolbar button, some predefined text - such as the date - is inserted into
the textbox at the point where the caret is. (It's assumed that the user will
be typing and then click the toolbar button.) From my research the textbox
control doesn't seem to support any method of querying the position of the
cursor. I've found documentation on pulling in the function "GetCaretPos"
from user32.dll and using that, but those examples seem to return coordinates
of the caret and not a linear position in the text. Is there a good way
anyone can think of to achieve this?

Thanks...

-Ben

Jun 26 '06 #3
"Ben R." <be**@newsgroup.nospam> schrieb:
I'm designing a winforms app in VB.NET 2.0 and have a textbox control and
also some toolbar buttons. I want to have it such that when the user
clicks a
toolbar button, some predefined text - such as the date - is inserted into
the textbox at the point where the caret is.


\\\
Me.TextBox1.SelectedText = "Hello World"
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 26 '06 #4
This is much easier than what I had devised using the selectionstart
property, which required me to do some math for where to insert and where to
place the cursor after. Thanks!
-Ben

"Herfried K. Wagner [MVP]" wrote:
"Ben R." <be**@newsgroup.nospam> schrieb:
I'm designing a winforms app in VB.NET 2.0 and have a textbox control and
also some toolbar buttons. I want to have it such that when the user
clicks a
toolbar button, some predefined text - such as the date - is inserted into
the textbox at the point where the caret is.


\\\
Me.TextBox1.SelectedText = "Hello World"
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 29 '06 #5

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

Similar topics

2
by: Thomas | last post by:
Hi there, I'd like to insert a text into a textarea at the current cursor position when you click on a button, but I only found out how to insert a text at the end of the textarea. Is it...
2
by: Lloyd | last post by:
I am trying to insert text in a text area. I need to insert one set of values on the left side of the text area and have corresponding values on the left side of the text area in an even column....
1
by: Carlos Lozano | last post by:
I need to merge the content of two richtextboxes. It can not be accomplished using the RichtTextBox.Text field because all format will be lost. So it has to be done using the RichtTextBox.Rtf...
2
by: Matt Tapia | last post by:
Is there a way to insert text into a multi-row textbox where the cursor position is at in the multi-row textbox? Just wondering
1
by: Matt Tapia | last post by:
Is there a way to insert text into a multi-row textbox where the cursor position is at in the multi-row textbox? Just wondering..I was told I could use the SelectedText property however I get...
6
by: Lelle | last post by:
Hello ! how can i insert text containg code examples from a textbox into a database using SQL insert statment. i have no problem to just add text that dont contains code and script examples...
4
by: jonathandrott | last post by:
hi, i'm trying to insert a textbox value into a access database. i get an error: 'Error: no value given for one or more required parameters.' nothing is set to be required in the db. is there...
2
by: azam841 | last post by:
Can We Insert A Textbox Into Listbox In Asp.net
4
by: Jeannot | last post by:
VS2008, VB, .NET 3.5 When I create a TextBox in Designer, then at runtime wherever I click, the caret is placed at the end of the text the box actually contains. But when I create a TextBox...
0
by: midhun singh | last post by:
Hi all, I have a little bit of a problem figuring out how to insert a textbox string from a VB.Net Windows form onto a Crystal Report. I have search through many articles and manuals for a way to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.