Home All Groups Group Topic Archive Search About

Help reading control.location value back form text file

Author
24 Nov 2006 8:44 PM
Marc
The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ?????????????????????. As it
wont accept a string value?



Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Save.Click
TW = System.IO.File.CreateText("C:\MyTextFile.txt")
Dim C As Control
For Each C In Me.Controls
If TypeOf C Is Button Then
TW.WriteLine(C.Text)
TW.WriteLine(C.Location)
End If
Next
TW.Close()
End Sub




Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Load.Click
Dim TextFileStream As System.IO.TextReader
TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")
Dim MyFileContents As String
Do
MyFileContents = TextFileStream.ReadLine
Dim test As New Button()
Me.Controls.Add(test)
test.Text = MyFileContents

test.Location = ????????????????????????????????

AddHandler test.MouseDown, AddressOf Me.Thebutton_MouseDown
AddHandler test.MouseMove, AddressOf Me.Thebutton_MouseMove
AddHandler test.MouseUp, AddressOf Me.Thebutton_MouseUp
Me.Controls.Add(test)
MsgBox(MyFileContents)
Loop Until MyFileContents = ""
TextFileStream.Close()
End Sub

Author
25 Nov 2006 9:22 AM
Tom Shelton
Marc wrote:
Show quoteHide quote
> The first part of the below writes the name and location of all
> buttons on a from to a text file. The second part reads that
> information back in and recreates the buttons. My problem is reading
> the location value back in where I marked ?????????????????????. As it
> wont accept a string value?
>
>
>
> Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Save.Click
> TW = System.IO.File.CreateText("C:\MyTextFile.txt")
> Dim C As Control
> For Each C In Me.Controls
> If TypeOf C Is Button Then
> TW.WriteLine(C.Text)
> TW.WriteLine(C.Location)
> End If
> Next
>  TW.Close()
> End Sub
>
>
>
>
> Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Load.Click
> Dim TextFileStream As System.IO.TextReader
> TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")
> Dim MyFileContents As String
> Do
> MyFileContents = TextFileStream.ReadLine
> Dim test As New Button()
> Me.Controls.Add(test)
> test.Text = MyFileContents
>
> test.Location = ????????????????????????????????
>
> AddHandler test.MouseDown, AddressOf Me.Thebutton_MouseDown
> AddHandler test.MouseMove, AddressOf Me.Thebutton_MouseMove
> AddHandler test.MouseUp, AddressOf Me.Thebutton_MouseUp
> Me.Controls.Add(test)
> MsgBox(MyFileContents)
> Loop Until MyFileContents = ""
> TextFileStream.Close()
> End Sub

Marc,

I think a better approach to this would be serialization.  Not of the
buttons it self, but of a container that controls the attributes...
something like (assuming 2005 here):

Option Strict On
Option Explicit On

<Serializable()> _
Friend Class AttributeContainer
    Public Location As Point
    Public Size As Size
    Public Text As String

    Public Sub New(ByVal Location As Point, ByVal Size As Size, ByVal
Text As String)
        Me.Location = Location
        Me.Size = Size
        Me.Text = Text
    End Sub
End Class

this class would hold the button values you wish to persist.  Then, to
save the attributes:

' a container
Dim btnList As List(Of AttributeContainer) = New List(Of
AttributeContainer)

' grab the attributes
For Each ctrl As Control In Me.Controls
    If TypeOf ctrl Is Button Then
                btnList.Add(New AttributeContainer(ctrl.Location,
ctrl.Size, ctrl.Text))
        End If
Next

' write the list in one chunk
Dim bf As New BinaryFormatter()
Using writter As FileStream = File.OpenWrite("myfile.dat")
    bf.Serialize(writter, btnList)
End Using

to retrieve would look something like:

Using reader As FileStream = File.OpenRead("myfile.dat")
    Dim bf As New BinaryFormatter
    Dim btnAttrs As List(Of AttributeContainer) =
DirectCast(bf.Deserialize(reader), List(Of AttributeContainer))

    For Each attr As AttributeContainer In btnAttrs
        Dim btn As New Button
                With btn
                    .Location = attr.Location
                    .Size = attr.Size
                    .Text = attr.Text
                End With
                Me.Controls.Add(btn)
        Next
End Using

HTH

--
Tom Shelton
Author
25 Nov 2006 10:42 AM
Marc
Fixed it, works great
added this..

Imports System
Imports System.Collections.Generic

Thanks again guys....BTW who are you guys? are you like the guardians
of VB code or something? I am over in the UK. Thanks again youve been a
big help

Tom Shelton wrote:
Show quoteHide quote
> Marc wrote:
> > The first part of the below writes the name and location of all
> > buttons on a from to a text file. The second part reads that
> > information back in and recreates the buttons. My problem is reading
> > the location value back in where I marked ?????????????????????. As it
> > wont accept a string value?
> >
> >
> >
> > Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Save.Click
> > TW = System.IO.File.CreateText("C:\MyTextFile.txt")
> > Dim C As Control
> > For Each C In Me.Controls
> > If TypeOf C Is Button Then
> > TW.WriteLine(C.Text)
> > TW.WriteLine(C.Location)
> > End If
> > Next
> >  TW.Close()
> > End Sub
> >
> >
> >
> >
> > Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Load.Click
> > Dim TextFileStream As System.IO.TextReader
> > TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")
> > Dim MyFileContents As String
> > Do
> > MyFileContents = TextFileStream.ReadLine
> > Dim test As New Button()
> > Me.Controls.Add(test)
> > test.Text = MyFileContents
> >
> > test.Location = ????????????????????????????????
> >
> > AddHandler test.MouseDown, AddressOf Me.Thebutton_MouseDown
> > AddHandler test.MouseMove, AddressOf Me.Thebutton_MouseMove
> > AddHandler test.MouseUp, AddressOf Me.Thebutton_MouseUp
> > Me.Controls.Add(test)
> > MsgBox(MyFileContents)
> > Loop Until MyFileContents = ""
> > TextFileStream.Close()
> > End Sub
>
> Marc,
>
> I think a better approach to this would be serialization.  Not of the
> buttons it self, but of a container that controls the attributes...
> something like (assuming 2005 here):
>
> Option Strict On
> Option Explicit On
>
> <Serializable()> _
> Friend Class AttributeContainer
>     Public Location As Point
>     Public Size As Size
>     Public Text As String
>
>     Public Sub New(ByVal Location As Point, ByVal Size As Size, ByVal
> Text As String)
>         Me.Location = Location
>         Me.Size = Size
>         Me.Text = Text
>     End Sub
> End Class
>
> this class would hold the button values you wish to persist.  Then, to
> save the attributes:
>
> ' a container
> Dim btnList As List(Of AttributeContainer) = New List(Of
> AttributeContainer)
>
> ' grab the attributes
> For Each ctrl As Control In Me.Controls
>     If TypeOf ctrl Is Button Then
>                 btnList.Add(New AttributeContainer(ctrl.Location,
> ctrl.Size, ctrl.Text))
>         End If
> Next
>
> ' write the list in one chunk
> Dim bf As New BinaryFormatter()
> Using writter As FileStream = File.OpenWrite("myfile.dat")
>     bf.Serialize(writter, btnList)
> End Using
>
> to retrieve would look something like:
>
> Using reader As FileStream = File.OpenRead("myfile.dat")
>     Dim bf As New BinaryFormatter
>     Dim btnAttrs As List(Of AttributeContainer) =
> DirectCast(bf.Deserialize(reader), List(Of AttributeContainer))
>
>     For Each attr As AttributeContainer In btnAttrs
>         Dim btn As New Button
>                 With btn
>                     .Location = attr.Location
>                     .Size = attr.Size
>                     .Text = attr.Text
>                 End With
>                 Me.Controls.Add(btn)
>         Next
> End Using
>
> HTH
>
> --
> Tom Shelton
Author
25 Nov 2006 9:28 AM
Cor Ligthert [MVP]
Marc,

First set Option Strict On in your program, than have a look at the property
"location".

http://msdn2.microsoft.com/en-gb/library/system.windows.forms.control.location.aspx

You see it are points, so to put it back you need first to set what is
written to points,
probably the top and left property are easier to start with,

Cor


Show quoteHide quote
"Marc" <marc_cro***@hotmail.com> schreef in bericht
news:1164401052.862295.13920@l39g2000cwd.googlegroups.com...
> The first part of the below writes the name and location of all
> buttons on a from to a text file. The second part reads that
> information back in and recreates the buttons. My problem is reading
> the location value back in where I marked ?????????????????????. As it
> wont accept a string value?
>
>
>
> Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Save.Click
> TW = System.IO.File.CreateText("C:\MyTextFile.txt")
> Dim C As Control
> For Each C In Me.Controls
> If TypeOf C Is Button Then
> TW.WriteLine(C.Text)
> TW.WriteLine(C.Location)
> End If
> Next
> TW.Close()
> End Sub
>
>
>
>
> Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Load.Click
> Dim TextFileStream As System.IO.TextReader
> TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")
> Dim MyFileContents As String
> Do
> MyFileContents = TextFileStream.ReadLine
> Dim test As New Button()
> Me.Controls.Add(test)
> test.Text = MyFileContents
>
> test.Location = ????????????????????????????????
>
> AddHandler test.MouseDown, AddressOf Me.Thebutton_MouseDown
> AddHandler test.MouseMove, AddressOf Me.Thebutton_MouseMove
> AddHandler test.MouseUp, AddressOf Me.Thebutton_MouseUp
> Me.Controls.Add(test)
> MsgBox(MyFileContents)
> Loop Until MyFileContents = ""
> TextFileStream.Close()
> End Sub
>
Author
25 Nov 2006 9:47 AM
Marc
Thanks guys!

I think I might stick to the way Ive done it as serialization looks a
bit hardcore for me.

So now I have....

MyFileContents = TextFileStream.ReadLine
            Dim test As New Button()
            test.Text = MyFileContents
            MyFileContents = TextFileStream.ReadLine
            test.Location = New Point(1, 2)
            Me.Controls.Add(test)


Which works fine. However I need a way for the test.location line to
read the string in form my text file? how can I do this?

i.e test.location = myfilecontents



Cor Ligthert [MVP] wrote:
Show quoteHide quote
> Marc,
>
> First set Option Strict On in your program, than have a look at the property
> "location".
>
> http://msdn2.microsoft.com/en-gb/library/system.windows.forms.control.location.aspx
>
> You see it are points, so to put it back you need first to set what is
> written to points,
> probably the top and left property are easier to start with,
>
> Cor
>
>
> "Marc" <marc_cro***@hotmail.com> schreef in bericht
> news:1164401052.862295.13920@l39g2000cwd.googlegroups.com...
> > The first part of the below writes the name and location of all
> > buttons on a from to a text file. The second part reads that
> > information back in and recreates the buttons. My problem is reading
> > the location value back in where I marked ?????????????????????. As it
> > wont accept a string value?
> >
> >
> >
> > Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Save.Click
> > TW = System.IO.File.CreateText("C:\MyTextFile.txt")
> > Dim C As Control
> > For Each C In Me.Controls
> > If TypeOf C Is Button Then
> > TW.WriteLine(C.Text)
> > TW.WriteLine(C.Location)
> > End If
> > Next
> > TW.Close()
> > End Sub
> >
> >
> >
> >
> > Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Load.Click
> > Dim TextFileStream As System.IO.TextReader
> > TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")
> > Dim MyFileContents As String
> > Do
> > MyFileContents = TextFileStream.ReadLine
> > Dim test As New Button()
> > Me.Controls.Add(test)
> > test.Text = MyFileContents
> >
> > test.Location = ????????????????????????????????
> >
> > AddHandler test.MouseDown, AddressOf Me.Thebutton_MouseDown
> > AddHandler test.MouseMove, AddressOf Me.Thebutton_MouseMove
> > AddHandler test.MouseUp, AddressOf Me.Thebutton_MouseUp
> > Me.Controls.Add(test)
> > MsgBox(MyFileContents)
> > Loop Until MyFileContents = ""
> > TextFileStream.Close()
> > End Sub
> >
Author
25 Nov 2006 9:57 AM
Tom Shelton
Marc wrote:
Show quoteHide quote
> Thanks guys!
>
> I think I might stick to the way Ive done it as serialization looks a
> bit hardcore for me.
>
> So now I have....
>
>  MyFileContents = TextFileStream.ReadLine
>             Dim test As New Button()
>             test.Text = MyFileContents
>             MyFileContents = TextFileStream.ReadLine
>             test.Location = New Point(1, 2)
>             Me.Controls.Add(test)
>
>
> Which works fine. However I need a way for the test.location line to
> read the string in form my text file? how can I do this?
>
> i.e test.location = myfilecontents
>


Well, if you don't want to do seralize (which I can send you a simple
working project if you want), then you will need to parse the contents
of the line to get the values for the x and y.  when you write out the
point like this, it will write out something like:

{x=100,y=2}

So, you might want to look into the strings Split method and then
Integer.Parse.

--
Tom Shelton
Author
25 Nov 2006 10:00 AM
Marc
OK,

Can u send me that serialization code then Tom?

what are the advantage sof serialization? I am planning to allow the
user to save and reload the contents of the txtfile at any time

Tom Shelton wrote:
Show quoteHide quote
> Marc wrote:
> > Thanks guys!
> >
> > I think I might stick to the way Ive done it as serialization looks a
> > bit hardcore for me.
> >
> > So now I have....
> >
> >  MyFileContents = TextFileStream.ReadLine
> >             Dim test As New Button()
> >             test.Text = MyFileContents
> >             MyFileContents = TextFileStream.ReadLine
> >             test.Location = New Point(1, 2)
> >             Me.Controls.Add(test)
> >
> >
> > Which works fine. However I need a way for the test.location line to
> > read the string in form my text file? how can I do this?
> >
> > i.e test.location = myfilecontents
> >
>
>
> Well, if you don't want to do seralize (which I can send you a simple
> working project if you want), then you will need to parse the contents
> of the line to get the values for the x and y.  when you write out the
> point like this, it will write out something like:
>
> {x=100,y=2}
>
> So, you might want to look into the strings Split method and then
> Integer.Parse.
>
> --
> Tom Shelton
Author
25 Nov 2006 10:12 AM
Marc
Tom,

I tried to insert your serialization code...

It has a few errors..one is that the type list is not defined (see ???
below) and the other is that file is not declared?

Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Save.Click
        ' a container
        Dim btnList As ???List??? (Of AttributeContainer) = New List(Of
AttributeContainer)
        ' grab the attributes
        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is Button Then
                btnList.Add(New AttributeContainer(ctrl.Location,
ctrl.Size, ctrl.Text))
            End If
        Next
        ' write the list in one chunk
        Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryFormatter()
        Using writter As IO.FileStream =
???File???.OpenWrite("C:myfile.dat")
            bf.Serialize(writter, btnList)
        End Using

    End Sub

    Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Load.Click
        Using reader As IO.FileStream = File.OpenRead("C:myfile.dat")
            Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryFormatter
        Dim btnAttrs As List(Of AttributeContainer) =
            DirectCast(bf.Deserialize(reader), List(Of
AttributeContainer))

            For Each attr As AttributeContainer In btnAttr
                Dim btn As New Button
                With btn
                    .Location = attr.Location
                    .Size = attr.Size
                    .Text = attr.Text
                End With
                Me.Controls.Add(btn)
            Next
        End Using
Marc wrote:
Show quoteHide quote
> OK,
>
> Can u send me that serialization code then Tom?
>
> what are the advantage sof serialization? I am planning to allow the
> user to save and reload the contents of the txtfile at any time
>
> Tom Shelton wrote:
> > Marc wrote:
> > > Thanks guys!
> > >
> > > I think I might stick to the way Ive done it as serialization looks a
> > > bit hardcore for me.
> > >
> > > So now I have....
> > >
> > >  MyFileContents = TextFileStream.ReadLine
> > >             Dim test As New Button()
> > >             test.Text = MyFileContents
> > >             MyFileContents = TextFileStream.ReadLine
> > >             test.Location = New Point(1, 2)
> > >             Me.Controls.Add(test)
> > >
> > >
> > > Which works fine. However I need a way for the test.location line to
> > > read the string in form my text file? how can I do this?
> > >
> > > i.e test.location = myfilecontents
> > >
> >
> >
> > Well, if you don't want to do seralize (which I can send you a simple
> > working project if you want), then you will need to parse the contents
> > of the line to get the values for the x and y.  when you write out the
> > point like this, it will write out something like:
> >
> > {x=100,y=2}
> >
> > So, you might want to look into the strings Split method and then
> > Integer.Parse.
> >
> > --
> > Tom Shelton
Author
25 Nov 2006 10:16 AM
Cor Ligthert [MVP]
Marc,

That serialization code is on our webside in the URL I gave you, I
simplified it from a longer one  from Tom. Instead of an Arraylist you can
take any object as long as it is serializable.

Cor

Show quoteHide quote
"Marc" <marc_cro***@hotmail.com> schreef in bericht
news:1164448842.412344.143580@14g2000cws.googlegroups.com...
> OK,
>
> Can u send me that serialization code then Tom?
>
> what are the advantage sof serialization? I am planning to allow the
> user to save and reload the contents of the txtfile at any time
>
> Tom Shelton wrote:
>> Marc wrote:
>> > Thanks guys!
>> >
>> > I think I might stick to the way Ive done it as serialization looks a
>> > bit hardcore for me.
>> >
>> > So now I have....
>> >
>> >  MyFileContents = TextFileStream.ReadLine
>> >             Dim test As New Button()
>> >             test.Text = MyFileContents
>> >             MyFileContents = TextFileStream.ReadLine
>> >             test.Location = New Point(1, 2)
>> >             Me.Controls.Add(test)
>> >
>> >
>> > Which works fine. However I need a way for the test.location line to
>> > read the string in form my text file? how can I do this?
>> >
>> > i.e test.location = myfilecontents
>> >
>>
>>
>> Well, if you don't want to do seralize (which I can send you a simple
>> working project if you want), then you will need to parse the contents
>> of the line to get the values for the x and y.  when you write out the
>> point like this, it will write out something like:
>>
>> {x=100,y=2}
>>
>> So, you might want to look into the strings Split method and then
>> Integer.Parse.
>>
>> --
>> Tom Shelton
>
Author
25 Nov 2006 2:51 PM
Tom Shelton
Marc wrote:
> OK,
>
> Can u send me that serialization code then Tom?
>
> what are the advantage sof serialization? I am planning to allow the
> user to save and reload the contents of the txtfile at any time
>

Well the main advantage I see is that 1 you don't have to parse text.
But, it's up to you.  The file in this case will not be a text file -
it will be a binary file.  You know what mark, I can't really see your
full email address - so I can't send it to you.  Can you see my email?
If you can, just drop a note to that address and I'll respond with an
attachment.

--
Tom Shelton
Author
25 Nov 2006 10:18 AM
Cor Ligthert [MVP]
I see now that I have given that link somewhere else where you have stated
this question.

Cor

Show quoteHide quote
"Marc" <marc_cro***@hotmail.com> schreef in bericht
news:1164448031.754589.90860@l12g2000cwl.googlegroups.com...
> Thanks guys!
>
> I think I might stick to the way Ive done it as serialization looks a
> bit hardcore for me.
>
> So now I have....
>
> MyFileContents = TextFileStream.ReadLine
>            Dim test As New Button()
>            test.Text = MyFileContents
>            MyFileContents = TextFileStream.ReadLine
>            test.Location = New Point(1, 2)
>            Me.Controls.Add(test)
>
>
> Which works fine. However I need a way for the test.location line to
> read the string in form my text file? how can I do this?
>
> i.e test.location = myfilecontents
>
>
>
> Cor Ligthert [MVP] wrote:
>> Marc,
>>
>> First set Option Strict On in your program, than have a look at the
>> property
>> "location".
>>
>> http://msdn2.microsoft.com/en-gb/library/system.windows.forms.control.location.aspx
>>
>> You see it are points, so to put it back you need first to set what is
>> written to points,
>> probably the top and left property are easier to start with,
>>
>> Cor
>>
>>
>> "Marc" <marc_cro***@hotmail.com> schreef in bericht
>> news:1164401052.862295.13920@l39g2000cwd.googlegroups.com...
>> > The first part of the below writes the name and location of all
>> > buttons on a from to a text file. The second part reads that
>> > information back in and recreates the buttons. My problem is reading
>> > the location value back in where I marked ?????????????????????. As it
>> > wont accept a string value?
>> >
>> >
>> >
>> > Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
>> > System.EventArgs) Handles Save.Click
>> > TW = System.IO.File.CreateText("C:\MyTextFile.txt")
>> > Dim C As Control
>> > For Each C In Me.Controls
>> > If TypeOf C Is Button Then
>> > TW.WriteLine(C.Text)
>> > TW.WriteLine(C.Location)
>> > End If
>> > Next
>> > TW.Close()
>> > End Sub
>> >
>> >
>> >
>> >
>> > Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
>> > System.EventArgs) Handles Load.Click
>> > Dim TextFileStream As System.IO.TextReader
>> > TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")
>> > Dim MyFileContents As String
>> > Do
>> > MyFileContents = TextFileStream.ReadLine
>> > Dim test As New Button()
>> > Me.Controls.Add(test)
>> > test.Text = MyFileContents
>> >
>> > test.Location = ????????????????????????????????
>> >
>> > AddHandler test.MouseDown, AddressOf Me.Thebutton_MouseDown
>> > AddHandler test.MouseMove, AddressOf Me.Thebutton_MouseMove
>> > AddHandler test.MouseUp, AddressOf Me.Thebutton_MouseUp
>> > Me.Controls.Add(test)
>> > MsgBox(MyFileContents)
>> > Loop Until MyFileContents = ""
>> > TextFileStream.Close()
>> > End Sub
>> >
>
Author
25 Nov 2006 10:27 AM
Marc
OK i think im nealry there....the only error I am getting is with this
pice of code

Dim btnList As List = New List(Of AttributeContainer)


as is cannot find 'List', not sure waht to replace it with?

Cor Ligthert [MVP] wrote:
Show quoteHide quote
> I see now that I have given that link somewhere else where you have stated
> this question.
>
> Cor
>
> "Marc" <marc_cro***@hotmail.com> schreef in bericht
> news:1164448031.754589.90860@l12g2000cwl.googlegroups.com...
> > Thanks guys!
> >
> > I think I might stick to the way Ive done it as serialization looks a
> > bit hardcore for me.
> >
> > So now I have....
> >
> > MyFileContents = TextFileStream.ReadLine
> >            Dim test As New Button()
> >            test.Text = MyFileContents
> >            MyFileContents = TextFileStream.ReadLine
> >            test.Location = New Point(1, 2)
> >            Me.Controls.Add(test)
> >
> >
> > Which works fine. However I need a way for the test.location line to
> > read the string in form my text file? how can I do this?
> >
> > i.e test.location = myfilecontents
> >
> >
> >
> > Cor Ligthert [MVP] wrote:
> >> Marc,
> >>
> >> First set Option Strict On in your program, than have a look at the
> >> property
> >> "location".
> >>
> >> http://msdn2.microsoft.com/en-gb/library/system.windows.forms.control.location.aspx
> >>
> >> You see it are points, so to put it back you need first to set what is
> >> written to points,
> >> probably the top and left property are easier to start with,
> >>
> >> Cor
> >>
> >>
> >> "Marc" <marc_cro***@hotmail.com> schreef in bericht
> >> news:1164401052.862295.13920@l39g2000cwd.googlegroups.com...
> >> > The first part of the below writes the name and location of all
> >> > buttons on a from to a text file. The second part reads that
> >> > information back in and recreates the buttons. My problem is reading
> >> > the location value back in where I marked ?????????????????????. As it
> >> > wont accept a string value?
> >> >
> >> >
> >> >
> >> > Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
> >> > System.EventArgs) Handles Save.Click
> >> > TW = System.IO.File.CreateText("C:\MyTextFile.txt")
> >> > Dim C As Control
> >> > For Each C In Me.Controls
> >> > If TypeOf C Is Button Then
> >> > TW.WriteLine(C.Text)
> >> > TW.WriteLine(C.Location)
> >> > End If
> >> > Next
> >> > TW.Close()
> >> > End Sub
> >> >
> >> >
> >> >
> >> >
> >> > Private Sub Load_Click(ByVal sender As System.Object, ByVal e As
> >> > System.EventArgs) Handles Load.Click
> >> > Dim TextFileStream As System.IO.TextReader
> >> > TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt")
> >> > Dim MyFileContents As String
> >> > Do
> >> > MyFileContents = TextFileStream.ReadLine
> >> > Dim test As New Button()
> >> > Me.Controls.Add(test)
> >> > test.Text = MyFileContents
> >> >
> >> > test.Location = ????????????????????????????????
> >> >
> >> > AddHandler test.MouseDown, AddressOf Me.Thebutton_MouseDown
> >> > AddHandler test.MouseMove, AddressOf Me.Thebutton_MouseMove
> >> > AddHandler test.MouseUp, AddressOf Me.Thebutton_MouseUp
> >> > Me.Controls.Add(test)
> >> > MsgBox(MyFileContents)
> >> > Loop Until MyFileContents = ""
> >> > TextFileStream.Close()
> >> > End Sub
> >> >
> >
Author
25 Nov 2006 2:46 PM
Tom Shelton
Marc wrote:
> OK i think im nealry there....the only error I am getting is with this
> pice of code
>
>  Dim btnList As List = New List(Of AttributeContainer)
>
>
> as is cannot find 'List', not sure waht to replace it with?
>

What version of VB are you using?  If it is 2005, then you need to
Import System.Collections.Generic.  If it is 2003 or earlier, then
you'll need to change that to an array list, and then cast when
retrieving the objects - since there was no support for generics in
2003 or ealier.

--
Tom Shelton
Author
25 Nov 2006 9:50 AM
Tom Shelton
Marc wrote:
> The first part of the below writes the name and location of all
> buttons on a from to a text file. The second part reads that
> information back in and recreates the buttons. My problem is reading
> the location value back in where I marked ?????????????????????. As it
> wont accept a string value?


By the way, I'm going to second Cor's advice.  If you aren't using
turning on Option Strict and Option Explicit, then do so.  It will make
your code easier to debug, since many errors will be caught at compile
time, and in many cases make your code run faster.

I will note that there is at least one exception to the Option Strict
On.  And that's doing late binding.  But, that should be a in a
specific file so and a concious decision.

--
Tom Shelton