Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Saving Forms...


Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2005, 08:35 PM
mntlnstituteflr mntlnstituteflr is offline
Regular
 
Join Date: Apr 2005
Posts: 69
Talking 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
Reply With Quote
  #2  
Old 07-28-2005, 11:44 PM
Ruffnekk's Avatar
Ruffnekk Ruffnekk is offline
Centurion
 
Join Date: Mar 2005
Location: Rotterdam, Netherlands
Posts: 167
Default

What kind of information should the file keep? The text properties and image names? Please specify.
__________________
Objection, your honor!
Who decides who's crazy?
http://www.freewebs.com/ruffnekk

Firefox Rox!
Reply With Quote
  #3  
Old 07-29-2005, 12:00 AM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

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.
Reply With Quote
  #4  
Old 07-29-2005, 12:00 AM
mrjeffy321 mrjeffy321 is offline
Ultimate Contributor
 
Join Date: Apr 2003
Location: Texas, USA
Posts: 1,623
Default

also for general info about file saving and reading,
File I/O In VB.Net
Reply With Quote
  #5  
Old 07-29-2005, 08:17 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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
Reply With Quote
  #6  
Old 07-30-2005, 11:29 AM
mntlnstituteflr mntlnstituteflr is offline
Regular
 
Join Date: Apr 2005
Posts: 69
Talking

So your saying that there is no way to save multiple components as one file, and then open it back up later?

Patrick Cason
Reply With Quote
  #7  
Old 07-31-2005, 06:48 AM
Fyreblade Fyreblade is offline
Newcomer
 
Join Date: Jul 2005
Location: Germany
Posts: 1
Default

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.
Reply With Quote
  #8  
Old 07-31-2005, 07:20 AM
jo0ls jo0ls is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2005
Location: London
Posts: 1,050
Default

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.
Reply With Quote
  #9  
Old 07-31-2005, 08:38 PM
mntlnstituteflr mntlnstituteflr is offline
Regular
 
Join Date: Apr 2005
Posts: 69
Talking

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->