Apologies if this is a basic question but I'm still experimenting with VB.net and I'm trying my hand at creating an event log for my test application. (Not Windows event Logs) - I've focused on one event, that being the time my application is launched.
I have two forms and I'm trying to establish a permanent "link" between Form1
and Form2
. This means that I can send .NET commands and variables to Form2
and on form close/open the data remains until the main application Form1
is closed.
Take for example the below code I'm running with Form1
is loaded.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.RichTextBox1.Text = ("Launched @ " & Now.ToShortTimeString())
End Sub
Form2
is not loaded until a Link Label titled "Event Log" is clicked within Form1
. I have a simple Form2
Load command for the click event on my Link Label.
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Form2.Show()
End Sub
Form2
consists of one RichText box, the aim of which I will add text on events of my choosing as I build the application.
Now when I debug my application I click my Link Label the test "Launched @ xx" appears in my RichTextBox - However when I close Form2
and then click my LinkLabel the RichTextBox is blank.
Main Questions
- I think this is being caused because the only time I'm generating
RichTextBox.Text
is when Form1 is loaded. This is a singular instance and closing/re-opening Form2 doesn't reload Form1 and so the commandForm2.RichTextBox1.Text = ("Launched @ " & Now.ToShortTimeString())
isn't ran again until I re-launch the whole application. - I researched a few answers like the one HERE. But using settings/XML doesn't appear to be a wise choice, I mean the Time is a unique value, can I use settings to reflect this?
MAIN NOTE - I'm planning for the event log to be cleared every time the application is closed, I will write the contents of the RichTextBox to a .txt file on application close.
Thanks for your advice, I would appreciate some documentation or code examples on saving strings/variables and using them between forms.