A Way for saving control with all of it's components and properties to a file or stream.

  • Thread starter Thread starter Mr. X.
  • Start date Start date
M

Mr. X.

Hello.
Is there any way to save a control + all of it's components to a file (or
give it some representation as a long string).

Thanks :)
 
Mr. X. said:
Hello.
Is there any way to save a control + all of it's components to a file
(or give it some representation as a long string).

Thanks :)

A control is an object with properties. You save the properties of the
object to a XML file manually. You instantiate the control/object (new),
and you populate the control/object from the XML file that represents
the controls properties. XML is string.
 
I would like to learn more about serialization.
The code I did is :
Dim f As System.IO.FileStream
Dim binFormat As New BinaryFormatter

f = nothing
try
f = New FileStream("items.txt", FileMode.Create)

binFormat.Serialize(f, MyPanel)
finally
f.close()
end try

MyPanel is declared as Panel. (dim myPanel as Panel ...)
Even I create myPanel as this :
Public Class MyPanelClass
Inherits Panel
Implements ISerializable

Public Sub GetObjectData(ByVal info As
System.Runtime.Serialization.SerializationInfo, ByVal context As
System.Runtime.Serialization.StreamingContext) Implements
System.Runtime.Serialization.ISerializable.GetObjectData
Dim i As Integer
i = 1 ' this code is not reachable **** what should I write
here. need an example, please ***********************
End Sub
End Class

....
dim myPanel as MyPanelClass
....

I need a simple sample (specifically : saving panel & objects on it).

Thanks :)
 
I would like to learn more about serialization.
The code I did is :
Dim f As System.IO.FileStream
Dim binFormat As New BinaryFormatter

f = nothing
try
f = New FileStream("items.txt", FileMode.Create)

binFormat.Serialize(f, MyPanel)
finally
f.close()
end try

MyPanel is declared as Panel. (dim myPanel as Panel ...)
Even I create myPanel as this :
Public Class MyPanelClass
Inherits Panel
Implements ISerializable

Public Sub GetObjectData(ByVal info As
System.Runtime.Serialization.SerializationInfo, ByVal context As
System.Runtime.Serialization.StreamingContext) Implements
System.Runtime.Serialization.ISerializable.GetObjectData
Dim i As Integer
i = 1 ' this code is not reachable **** what should I write
here. need an example, please ***********************
End Sub
End Class

...
dim myPanel as MyPanelClass
...

I need a simple sample (specifically : saving panel & objects on it).

Thanks :)

Well, you serialize classes which are marked with "<Serialiable()>"
attribute such as arrays and strings, in that case the panel base
class doesn't seem to have this attribute and thus its members cannot
be serialized, and you'll get SerializationException error.

http://msdn.microsoft.com/en-us/library/system.windows.forms.panel.aspx

If your own class or any .NET class had this attribute, you could
easily have serialized and deserialized its fields/members like in the
followings:

http://devcity.net/Articles/113/1/dotnet_serialization.aspx
http://devcity.net/Articles/113/1/dotnet_serialization.aspx
http://www.java2s.com/Tutorial/VB/0240__Stream-File/0480__Binary-Serialization.htm


HTH,

Onur Güzel
 
I need a way for saving the panel and all of it's component to a file.
I understand that Panel is not serializable, but I didn't find any trick to
make it be one.
I read the article you gave, but didn't find any way for saving the panel.

Also did :
dim prs() As System.Reflection.PropertyInfo
Dim cc
....
dim myPanel as Panel
....
For i = 0 To MyPanel.Controls.Count - 1
prs = MyPanel.controls(i).GetType().GetProperties()
For j = 0 To prs.Count - 1
If prs(j).CanRead AndAlso prs(j).CanWrite() Then
cc = prs(j).GetValue(c.ActiveControl, Nothing) '
*****
end if
next j
next I

The inner loop (with the asterisks) doesn't retrieve the properties exactly
as I retrieve on design time (property window).
I don't need something too much complicated - just to translate to a stream,
that can store on a database.

Thanks :)
 
In other words, is how can I serialize a panel.
If this cannot be done, so how can I search all of its properties exactly as
they are seen on the property editor ?
Thank :)
 
Back
Top