-
Nov 24th, 2020, 01:06 AM
#1
Thread Starter
Lively Member
Saving an edited Windows Form GUI
Hi guys,
How do I save a form which programmatically adds objects onto the GUI, when after I close I can get it to its latest form?
So here's an example code:
vb.net Code:
Private Sub Form1_Click(sender As Object, e As MouseEventArgs) Handles MyBase.Click
Dim newTB As New TextBox
newTB.Name = "tbNew" & objectcounter
'Set location, size and so on if you like
Me.Controls.Add(newTB)
Dim x = e.Location.X
Dim y = e.Location.Y
newTB.Location = New Point(x, y)
End Sub
So after adding a few textboxes on the form, and after exiting, I'd like to be able to save its latest form and continue from there.
Is this possible?
Thanks
Vizier87
-
Nov 24th, 2020, 02:45 AM
#2
Re: Saving an edited Windows Form GUI
No it's not possible, from the point of view of the form class that is defined in your application. Whatever you create in the designer and the code window before you build is the class so that's what gets created when you instantiate that class. Anything else has to be done in code after that. Just like anything else, if you want to "save" actions that the user takes in your application then you need to save that to a file or a database or the like. If you want the user to be able to add TextBoxes to your form at run time then you might store the Bounds of each of those TextBoxes to a text file. At startup, you read that text file and create a TextBox for each value with the Bounds based on that value. The specifics are up to you but that's the principle that you need to implement.
-
Dec 1st, 2020, 09:50 PM
#3
Thread Starter
Lively Member
Re: Saving an edited Windows Form GUI
Originally Posted by jmcilhinney
Just like anything else, if you want to "save" actions that the user takes in your application then you need to save that to a file or a database or the like. If you want the user to be able to add TextBoxes to your form at run time then you might store the Bounds of each of those TextBoxes to a text file. At startup, you read that text file and create a TextBox for each value with the Bounds based on that value.
Sounds like quite a task.
So if I understood you correctly, here's the principle:
1. Save the "parameters" in a text file
2. Run the form to read the "parameters" (let's say a textbox, length of the object, position, etc)
3. Done.
I've been googling around for something to achieve this but haven't found any (my search was "create objects from text file bounds vb.net").
Any keywords or links that may be of help?
I'd like to just be able to create the objects just by running from a saved text file with the "params" as you mentioned.
-
Dec 1st, 2020, 10:06 PM
#4
Re: Saving an edited Windows Form GUI
Originally Posted by Vizier87
Sounds like quite a task.
Not really.
Originally Posted by Vizier87
So if I understood you correctly, here's the principle:
1. Save the "parameters" in a text file
2. Run the form to read the "parameters" (let's say a textbox, length of the object, position, etc)
3. Done.
Basically, yes.
Originally Posted by Vizier87
I've been googling around for something to achieve this but haven't found any (my search was "create objects from text file bounds vb.net").
Any keywords or links that may be of help?
I'd like to just be able to create the objects just by running from a saved text file with the "params" as you mentioned.
Stop expecting magic. Break the problem down into parts and tackle each part individually. Creating a control in code is the same regardless, so first learn how to do that. Once you can do that, you will know what parameters you'll need. You can then write a method that takes those values as arguments and then you can call that method with the appropriate arguments no matter where the values come from. Boom! that part is done.
Now, completely separately, you can work out how to store the required values in a file, how read that data from a file and how to convert it to the required form, e.g. read text and convert it to numeric size and location values that you can then pass into the method you wrote earlier.
This is how you need to approach EVERY programming problem: divide and conquer. Don't expect to find an "example" of the exact end-to-end process that you're trying to implement. Instead, break that process down into its constituent parts, learn what you can about each of those and try implementing each one separately. You can then ask a question about one specific part that you're having trouble with to solve that specific problem. Once you have solved all the subproblems, you simply combine the solutions into one and you've inherently solved the original problem. The is problem-solving 101 and is not specific to programming.
-
Dec 1st, 2020, 10:45 PM
#5
Thread Starter
Lively Member
Re: Saving an edited Windows Form GUI
Thanks. You got me thinking again and yeah I have to admit I was lazy to think of this really quite a simple thing actually.
So I just loaded a saved text file and voila upon this stone I'll build my throne.
vb.net Code:
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText("bla bla bla \Metadata.txt")
Dim object_type = fileReader.Split(",")(0)
Dim x = fileReader.Split(",")(1)
Dim y = fileReader.Split(",")(2)
If object_type = "Textbox" Then
Dim newTB As New TextBox
newTB.Name = "tbNew" & objectcounter
'Set location, size and so on if you like
Me.Controls.Add(newTB)
newTB.Location = New Point(x, y)
End If
I guess this is why people have their own database file formats.. if I just make it into a text file it might be easily messed up by some rascal.
-
Dec 1st, 2020, 11:08 PM
#6
Re: Saving an edited Windows Form GUI
Those wabbits can indeed be wascally.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|