|
G'day and thanx in advance for anyone replying to my question.
Being a VB.Net newbie, I am having trouble using basic text extraction from a richtextbox.
As the user types into a richtext box I have a tool tip that pops up when the user hits '(' and closes on the ')' key hits. It appears just below and to the right of the current caret location in the richtextbox.
I would like to be able to extract the last word typed just prior to hitting the '(' key, so I know what they are trying to do and can provide appropriate tips in the tooltip.
Can anyone help me with a short example of extracting text from the current caret position - 1, to the last '$', " " , "<", ";" entered before the current caret position.
Sorry if it's a real Newb question, .NET has so many bloody classes, I'm sure there's a simple way to do it, but I don't know where to look.
Cheers, Craig.
|
|
|
|
|
The current Caret position is always stored in the SelectionStart property of the RichTextBox control.
Now, the Text() property will return the text as a String object. You can then use its LastIndexOfAny(char(), startIndex, count) method, using 1 for startIndex and the value of SelectionStart for the count, to find the index of the last character, which you've already supplied in your post. This will give to the starting position and ending position of the word your looking for.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
G'day Dave,
Thanks heaps for a super fast response, and sorry for my tardiness in thanking you.
I'm stunned at how quick I have received help from these forums. It's guys like you, willing to read these and provide help, that make it all work.
Thanks again.
Craig.
|
|
|
|
|
4 more to go!
Then it's the WEEKEND!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Craig
Your question is similar to having autoselect in a Combobox.You can extend the same idea over here using the keypress event.
Private Sub TextBox1_Keypress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
If Char.IsControl(e.KeyChar) Then Return
With Me.TextBox1
Dim ToFind As String = .Text.Substring(0, .SelectionStart) & e.KeyChar
End With
End Sub
the variable toFind will have previous characters in textbox and the currently typed character.for eg:- if the textbox contains "chr" and user types "i" then the value of to find will be "Chri".
I think this should solve your problem.
Mandar Patankar
Microsoft Certified professional
|
|
|
|
|
G'day Mandar,
Thanks very much for that. I haven't tried it yet, but it reads well, it's simple and seems to make sense. You're obviously skilled in VB .NET
I did pick up on a neat little trick you're using, which I havn't seen anywhere else....the 'With' and 'End With' Statement. It appears from your code that it basically saves us from typing Me.TextBox1 within the 'With'-'End With'. That in itself is a bit of gold !
With Me.TextBox1
Dim ToFind As String = .Text.Substring(0, .SelectionStart) & e.KeyChar
End With
Also, just a quick comment about how fast I received 2 very clever responses to my question. I received the first response in a matter of an hour or two and the second not long after. The 'CodeProject' has been a huge help. Cheers to the admin as well.
Craig.
|
|
|
|
|
I'm writing an application(VB) that connect to a trading server, I have the following code, but I am havign some strange behaviour:
Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
' assume this is a non Financial Advisor account. If it is the managedAccounts()
' event will be fired.
m_faAccount = False
m_dlgConnect.Show()
If m_dlgConnect.ok Then
With m_dlgConnect
Call TwsCtrl.connect(.hostIP, .port, .clientId)
End With
End If
End Sub
When this code is executed, the result that I want, namely to logon the server, I am having to run this code twice, I mean it works, but The command button that I press to execute this code requires me to have to press it twice, requiring this module to execute twice???? I cant quite figure why I get this strange behaviour??
|
|
|
|
|
Since you've provided no information about the service your trying to connect to and what this .connect method does exactly, there's nothing anyone can tell you to help.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i am making a program in vb.net suing ado.net on which i m using MS-Access as database "db1".
now, i want to get the name of all tables in db1 in combobox
plz help me
rememberi m using MS access
|
|
|
|
|
|
i am writing a program where i have to do conversion from
double to string
which function i should use
i tried toString method but it did not work
so help me
|
|
|
|
|
sumit21 wrote:
i tried toString method but it did not work
Either you did something wrong or your expectation of what it should do are wrong. Without a sample of the code you tried or what you wanted it to do, there's nothing we can really comment on.
Dim myDouble As Double = 3.1415927
Console.WriteLine( "myDouble = " & myDouble.ToString() )
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a class built into VB.net that will allow me to discover the file, folder, & registry key permissions?
Thanx in advance for any guidance in the correct direction.
-Mark-
|
|
|
|
|
No.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I load Images into ImageList, but in runtime i checked there is no image in ImageList.. What s problem thank u
|
|
|
|
|
Since the ImageList control is pretty finicky to begin with, it's nearly impossible to tell you what wrong without seeing any of your code that is filling the ImageList. Another question would be, are you using Application.EnableVisualStyles?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I fill imagelist at design time. when i check imagelist1.imagestream,it is nothing at run time .i intend to use Application.EnableVisualStyles But i tried both case(using EVS and not using EVS),Nothing changed.
if i fill imageList at run time, it is working. But i have to save ico files in to the project folder in this case. But i dont wantto do this. what Can u offer me ?
|
|
|
|
|
Hi All,
How to make Scrollable image with Picturebox Control,
means insert scrollbar with the picturebox.
plz give code too if possible.
thanx in advance
Sajjad
|
|
|
|
|
You wont need any code at all
1. Drag a Panel on the form and set its AutoScroll property to true.
2. Drag a PictureBox into the panel at the top left position (0,0) and set its SizeMode to AutoSize .
3. Assign a big picture to the picture box and be happy
|
|
|
|
|
|
HI
I m designing one application for one company as my final year project.
I want to know that how can i send employee No.(In the login form as user name) to other form to display the information of that employee from database.
Simply speaking i want to send Value of employee No field in login form to EMPLOYEE INFO form to display the info of that employee.
Please give me response as fast as possible.
|
|
|
|
|
|
Hi All,
Plz tell me, how can draw rectangle on image with any event.
means,if anyone click on button 1, so rectangle draw on specific position in the Image or anyone Enter the textbox 1, so rectangle draw on specific position in the image.
plz discuss in detail
Thanx in advance
Sajjad
|
|
|
|
|
You will need a Graphics object for the image and then you can draw directly into it:
using (Graphics g = Graphics.FromImage(myImage)) {
g.DrawRectangle(new Pen(Color.Black), 10, 10, 20, 20);
}
|
|
|
|
|
Code for Keyboard hooks in VB .Net
|
|
|
|