Create OpenFileDialog when RichTextBox selected? - vb.net

In my application, a list of fields is read from a database, and then rendered in a TabControlPage. Each field has a Control of a specific type, one of which is a RichTextBox.
What I need, is when the user selects the RichTextBox, an OpenFileDialog should appear, allowing the user to select a file. The RichTextBox should then display the full path + filename(eg. C:/files/excel/thing.xlsx) in the form of a hyperlink.
Currently, you can type in the path+filename into the RichTextBox and it will automatically be made into a hyperlink.
Any suggestions, or perhaps reference material you can give me?

You can attach something like this to the Enter event on your RichTextBox:
Dim dialog As New OpenFileDialog()
Dim result As DialogResult = dialog.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
RichTextBox1.Text = dialog.FileName
End If
This is not turning it into a hyperlink for me, but it sounds like you have that part handled?
edited as per Lars' comment.

Related

How to save textbox text to notepad and save again a textbox text to add it into the same note pad?

I want to save my textbox1.text in a notepad of my computer. And after saving that, I will save the next textbox1.text again. But I want it to be added to the same notepad. Anyone can help me on the code? Using VB net.
I have a one form with controls and all entries will be displayed on one textbox. I want to save that textbox but I don't know how.
You could use the File.AppendAllText method to save the text to a file:
Public Sub SaveTextToFile(FilePath As String, Text As String)
System.IO.File.AppendAllText(FilePath, Text)
End Sub
Here is an example of using the method:
SaveTextToFile("C:\New.txt", textBox1.Text)

How to change the order controls are read in .Net?

I have a very textbox rich heavy panel (approx ~ 25 textboxes) for which I want to retrieve all my text from.
I've done so using this loop.
Dim AllItemsArray As New ArrayList
For Each txt As Control In Panel2.Controls
If txt.GetType Is GetType(TextBox) Then
AllItemsArray.Add(txt.Text)
End If
Next
However, for some odd reason it reads the textboxes in a completly random order which makes using the information extremely difficult.
I thought that the textboxes were read in the order they are made, but so far it hasn't done so.
Does anyone have any suggestions as to how I can alter it so that it reads the textboxes in order?
IE. textbox1.text, textbox2.text ...etc
and not
textbox5.text, textbox2.text, textbox 20 ....etc
Thanks
This gets the controls in Tab order sequence. It also gets controls that are in containers, i.e. GroupBox.
Dim ctrl As Control = Me.GetNextControl(ctrl, True)
Do While ctrl IsNot Nothing
Debug.WriteLine(ctrl.Name)
ctrl = Me.GetNextControl(ctrl, True)
Loop

check if richtextbox contains textbox

I want to create a very simple login form is VB
All of the usernames are in a textfile on my webserver.
So first the program downloads that textfile with:
Dim wc As New WebClient()
Dim datawc.DownloadString("url.txt")
After that my program put the the text in a richbox with
RichTextBox1.Text = data
Then the programs checks if the text that is entered in the textbox is also in the richtextbox.
Now the problem is that if i fill in the textbox 1122, and in the richtextbox is 1133 that the program returns a correct response.
Sorry for my bad english
I just fixed it myself by using this condition
If data.Contains(TextBox1.Text) Then

How to save changes of a saved text file in VB.NET

I have a text editor that can open text files .txtand puts the text in a textbox. The user can also save the text to a .txt file.
How can the user save the changes of that text file that was saved recently?
Also, If the user opened a txt file how can the text editor change the text file to what the user changed?
Hope you understood that. Thanks in advance.
Since I don't know what you've done so far I will take this from the beginning...
For this you will need these components:
A SaveFileDialog
An OpenFileDialog
Three buttons (or menuitems), labeled: "Save", "Save As", "Open"
And I actually recommed using a RichTextBox instead of a regular TextBox.
.
To start, we put a variable in the code to know what file was saved before:
Dim LatestFile As String
Then, go to the properties of your Save- and OpenFileDialog and put this in the Filter field:
Text files (*.txt)|*.txt
Then you double-click the SaveFileDialog which should write the SaveFileDialog_FileOk event in your code. There you put:
LatestFile = SaveFileDialog1.FileName
RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then double-click the OpenFileDialog, and enter this code:
LatestFile = OpenFileDialog1.FileName
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then for the buttons:
The "Open" button:
OpenFileDialog1.ShowDialog()
The "Save" button:
If Not LatestFile = "" Then
RichTextBox1.SaveFile(LatestFile, RichTextBoxStreamType.PlainText)
Else
SaveFileDialog1.ShowDialog()
End If
And the "Save As" button:
SaveFileDialog1.ShowDialog()
.
Hope this helps!
If I understood your question: you want your text editor application to detect changes that happened to the source text file that it is currently viewing to the user and if it detects a change, it should update its text box to display the latest file for the user.. am I right?
If that is the case, one way to do that is to use a Timer. Every time the timer tick event is triggered, you should check the date of the last modification to the file. If it is greater than the date that you have checked while opening the file for the first time, then the file had gone through some changes. Reload the file contents into the text box.
Another way (without using Timers) is to only check for the modification date once the application window is activated. Since the user will have to change the focus of the program to, say Notepad to do changes to the text file, then once the user returns focus to the Text Editor Application, use the Window Activate or Click event to check the file modification date.

Adding text to an existing textbox in a word document VB.Net

My company creates a welcome packet for each new employee. In this packet, it's our job to list their name, job title, etc. We use a template for this; just a page within the word document that has textboxes for each field.
Is it possible to add info to those existing textboxes? If not, how can I re-create the page in the document with new textboxes? It's the 3rd page.
I don't know if this is even possible, but if it is please let me know.
Assume your textbox is called Textbox1. To add text to it simply write:
TextBox1.text = Textbox1.text & "String here"
Alternatively, if you want to wipe it out completely, go for
Textbox1.text = "String here"
Hope this helps!