|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 Look at the 'SelectionStart' property.
-- Show quoteHide quoteTerry "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 Thanks!
textBox1.Text = textBox1.Text.Insert(textBox1.SelectionStart, "Test"); worked beautifully... -Ben Show quoteHide quote "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 "Ben R." <benr@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/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" wrote: > "Ben R." <benr@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/> > >
ASP.NET web application - date conversions UK date format?
Building a single EXE file in VB 2005? What errors are not trappable? default in .NET byref or byval? Build Failed - 0 Errors DataGridView row background color Adding ActiveX controls at runtime and threading How to gain access to objet in different class ? Define a compilation switch Listbox help |
|||||||||||||||||||||||