 |
 |

07-28-2005, 08:35 PM
|
|
Regular
|
|
Join Date: Apr 2005
Posts: 69
|
|
Saving Forms...
|
Hey everyone,
I am wondering how to save the form as a file format that I will be making. In other words, I have 6 picture boxes, 6 text boxes, and 6 buttons on a form, and I want to save all of the information from that form as a new file.
Source is offered if needed. Here's all I've tried:
Code:
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
SaveFileDialog1.ShowDialog()
End Sub
Thanks,
Patrick Cason
|
|

07-28-2005, 11:44 PM
|
 |
Centurion
|
|
Join Date: Mar 2005
Location: Rotterdam, Netherlands
Posts: 167
|
|
|
What kind of information should the file keep? The text properties and image names? Please specify.
|
|

07-29-2005, 12:00 AM
|
 |
Contributor
|
|
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
|
|
|
Your first step needs to be to learn how to read and write files in VB.NET. Once you can write to a file, and read back from a file, you will be able to store properties such as width, height, text, etc - as Ruffnekk suggests.
There are plenty of tutorials on the net about reading and writing using IO.StreamReader and IO.StreamWriter that you can check out.
|
|

07-29-2005, 12:00 AM
|
|
Ultimate Contributor
|
|
Join Date: Apr 2003
Location: Texas, USA
Posts: 1,623
|
|
|

07-29-2005, 08:17 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
Or using serialization you can save the entire form in a simple step.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

07-30-2005, 11:29 AM
|
|
Regular
|
|
Join Date: Apr 2005
Posts: 69
|
|
|
So your saying that there is no way to save multiple components as one file, and then open it back up later?
Patrick Cason
|
|

07-31-2005, 06:48 AM
|
|
Newcomer
|
|
Join Date: Jul 2005
Location: Germany
Posts: 1
|
|
Quote:
|
Originally Posted by wayneph
Or using serialization you can save the entire form in a simple step.
|
I thought, It was impossible to serialize a control in .Net ...
How do you want that to realise without creating new classes which inherit all the controls you need (which is , as far as I know, possible, but less functional than the "old-school" way)?
Fyreblade
Edit: I've got to improve myself: It would be possible, if there weren't any other objects declared in the control, which aren't able to serialize either. So I think you've got to save each property separately...
|
Last edited by Fyreblade; 07-31-2005 at 06:53 AM.
|

07-31-2005, 07:20 AM
|
|
Senior Contributor
Forum Leader * Expert *
|
|
Join Date: Feb 2005
Location: London
Posts: 1,050
|
|
Code:
Dim stringToWriteToFile As String
Private Sub SaveControls()
For Each ctrl As Control In Me.Controls
Select Case ctrl.GetType.ToString
Case "System.Windows.Forms.Button"
AddButtonToFile(ctrl)
'repeat with function for all control types
End Select
Next
'now save the string to a file ...
End Sub
Private Sub AddButtonToFile(ByVal ctrl As Control)
Dim thisButton As Button
thisButton = DirectCast(ctrl, Button)
stringToWriteToFile &= thisButton.Name & ","
stringToWriteToFile &= thisButton.Location.X & ","
stringToWriteToFile &= thisButton.Location.Y & ","
stringToWriteToFile &= thisButton.Width & ","
stringToWriteToFile &= thisButton.Height & ","
'..etc...
'last one for this control:
stringToWriteToFile &= thisButton.Text & vbCrLf 'start new line for next control
End Sub
should get you started...
note: Common properties such as location could be retrieved with ctrl.Location. You need to do the direct cast to get properties specific to a control type, so ctrl.image won't work, but if you cast the ctrl to a picturebox with
thisPicturebox = directcast(ctrl,picturebox)
..then you can use thisPictureBox.image
|
Last edited by jo0ls; 07-31-2005 at 08:31 AM.
|

07-31-2005, 08:38 PM
|
|
Regular
|
|
Join Date: Apr 2005
Posts: 69
|
|
I'm sorry I don't get it, I tried the code, but it didn't work and was too confusing  . I just thing I need to learn a little more before I can deal with the big coding  .
I don't really need the code now, but thanks anyway!
Patrick Cason
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|