|
-
Mar 29th, 2004, 11:52 AM
#1
Thread Starter
Hyperactive Member
-
Mar 29th, 2004, 11:54 AM
#2
Sleep mode
Do it this way . Location encapsulate the "X" and "Y" of the form .
VB Code:
Dim position As Point = Me.Location
-
Mar 29th, 2004, 12:13 PM
#3
Thread Starter
Hyperactive Member
Thanks Pirate it works
The code snipets looking now - but as you can see in the outputfile
<?xml version="1.0"?>
<Point xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<X>0</X>
<Y>0</Y>
</Point>>
where is the size of the window????
VB Code:
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'Prüfen ob App wirklich beendet werden soll
If MessageBox.Show(Application.ProductName & " schliessen?", Application.ProductName & " - Info", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.No Then
e.Cancel = True
End If
Dim xs As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
xs.Serialize(fs, Me.Location)
fs.Close()
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mstrAppTitle = Application.ProductName & " " & Application.ProductVersion & " - (" & Application.StartupPath & ")"
Me.Text = mstrAppTitle
If IO.File.Exists("form.config") Then
Dim xs As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
Dim pt As Point = Me.Location
fs.Close()
Me.Location = pt
End If
End Sub
-
Mar 29th, 2004, 12:20 PM
#4
Sleep mode
I thought you're wanting to save the location of the form . Here's how to get the size of the form in a Size variable .
VB Code:
Dim siz As Size = Me.Size
-
Mar 29th, 2004, 12:30 PM
#5
Thread Starter
Hyperactive Member
Size and Location
tried the t hing with the Me.Size but got error
-
Mar 29th, 2004, 12:32 PM
#6
Sleep mode
Originally posted by Bongo
Size and Location
tried the t hing with the Me.Size but got error
What does the error say and where did you put that code ?
-
Mar 29th, 2004, 12:51 PM
#7
Thread Starter
Hyperactive Member
the closing method looks like to work (see below) but
the loading seems not to work.
<?xml version="1.0"?>
<Point xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<X>14</X>
<Y>-1</Y>
</Point><?xml version="1.0"?>
<Size xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Width>996</Width>
<Height>715</Height>
</Size>
I tried xsLocation.de
VB Code:
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim xsLocation As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim xsSize As New Xml.Serialization.XmlSerializer(GetType(Size))
Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
xsLocation.Serialize(fs, Me.Location)
xsSize.Serialize(fs, Me.Size)
fs.Close()
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists("form.config") Then
Dim xsLocation As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim xsSize As New Xml.Serialization.XmlSerializer(GetType(Size))
Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
Dim ptLocation As Point = xsLocation.Deserialize(fs) ' Me.Location
Dim ptSize As Size = xsSize.Deserialize(fs) ' Me.Size
fs.Close()
Me.Location = ptLocation
Me.Size = ptSize
End If
End Sub
-
Mar 29th, 2004, 01:13 PM
#8
Sleep mode
Try to put the load event code in the constructor if still doesn't work , try putting it in the OnLoad method of the form . btw , are you sure you're getting the correct values from the file ? You maybe need to check them using messagebox .
-
Mar 29th, 2004, 01:35 PM
#9
Thread Starter
Hyperactive Member
The values are correct writen to the file.
the prob is in the load meth. see comments in code.
The meaning of the msg in english is:
Option Strict on does not allow a impliziert convercion of
System.Objects in System.Drawing.point.
VB Code:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists("formLocation.config") Then
Dim xsLocation As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim fsLocation As New IO.FileStream("formLocation.config", IO.FileMode.OpenOrCreate)
'the next line gives the error
'E:\...\frmMain.vb(95): 'Option Strict On' lässt keine impliziten Konvertierungen von System.Object in System.Drawing.Point zu.
Dim ptLocation As Point = xsLocation.Deserialize(fsLocation) ' Me.Location
Me.Location = ptLocation
fsLocation.Close()
End If
If IO.File.Exists("formSize.config") Then
Dim xsSize As New Xml.Serialization.XmlSerializer(GetType(Size))
Dim fsSize As New IO.FileStream("FormSize.config", IO.FileMode.OpenOrCreate)
'the next line gives the error
'E:\...\frmMain.vb(95): 'Option Strict On' lässt keine impliziten Konvertierungen von System.Object in System.Drawing.Point zu.
Dim ptSize As Size = xsSize.Deserialize(fsSize) ' Me.Size
Me.Size = ptSize
End If
-
Mar 29th, 2004, 01:59 PM
#10
Sleep mode
Use DirectCast function that forces the conversion .
VB Code:
DirectCast(xsLocation.Deserialize(fsLocation), Point)
Check file names , I think the chunk code inside the if structure isn't executed .
-
Mar 29th, 2004, 02:33 PM
#11
Thread Starter
Hyperactive Member
It works
Thanks Pirate,
I put the to working procedures _Closing and _Load below for
the fellow developers with the same prob.
Thanks again.
BTW would it work if I put all in one file? and if yes how?
VB Code:
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'Prüfen ob App wirklich beendet werden soll
If MessageBox.Show(Application.ProductName & " schliessen?", Application.ProductName & " - Info", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.No Then
e.Cancel = True
End If
Dim xsLocation As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim fsLocation As New IO.FileStream("fLocation.config", IO.FileMode.OpenOrCreate)
xsLocation.Serialize(fsLocation, Me.Location)
fsLocation.Close()
Dim xsSize As New Xml.Serialization.XmlSerializer(GetType(Size))
Dim fsSize As New IO.FileStream("fSize.config", IO.FileMode.OpenOrCreate)
xsSize.Serialize(fsSize, Me.Size)
fsSize.Close()
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mstrAppTitle = Application.ProductName & " " & Application.ProductVersion & " - (" & Application.StartupPath & ")"
Me.Text = mstrAppTitle
If IO.File.Exists("fLocation.config") Then
Dim xsLocation As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim fsLocation As New IO.FileStream("fLocation.config", IO.FileMode.OpenOrCreate)
Dim ptLocation As New System.Xml.XmlTextReader(fsLocation)
Me.Location = DirectCast(xsLocation.Deserialize(ptLocation), Point)
fsLocation.Close()
End If
If IO.File.Exists("fSize.config") Then
Dim xsSize As New Xml.Serialization.XmlSerializer(GetType(Size))
Dim fsSize As New IO.FileStream("FSize.config", IO.FileMode.OpenOrCreate)
Dim ptSize As New System.Xml.XmlTextReader(fsSize)
Me.Size = DirectCast(xsSize.Deserialize(ptSize), Size)
fsSize.Close()
End If
End Sub
-
Mar 29th, 2004, 02:54 PM
#12
-
Mar 29th, 2004, 03:02 PM
#13
Thread Starter
Hyperactive Member
I think so as well, as i mentioned before I saw this now in a few
postings. It is verry bad to write with VB.Net to the registry.
(I was writing all the years to the reg and I and my clients
been happy about this)
But this is a new topic and I dont want to be guilty
starting a holly war between the followers of this message and the others.
What i think is a good approch is to write a methode and passing
the values to this funktion.
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
|