Saving Location and Size to Text Fiels into Database

M

Marcolino

Hi all,
I have a simple problem but I don't know which is the best way to
solve it.
I need to savo into a table into access DB the location and the size
of a form.
Is there a way to save Location and Size into a single text field, on
I need 4 Field X,Y,Height and Width?
If yes, how can convert Location and Size into String and then Back to
a Location and Size to apply back to the form?

Many Thanks
 
K

kimiraikkonen

Hi all,
I have a simple problem but I don't know which is the best way to
solve it.
I need to savo into a table into access DB the location and the size
of a form.
Is there a way to save Location and Size into a single text field, on
I need 4 Field X,Y,Height and Width?
If yes, how can convert Location and Size into String and then Back to
a Location and Size to apply back to the form?

Many Thanks

Hi,
Sure it's possible. Forms have "location" and "size" property and you
can get them as strings.

' Assign size/location of current form to strings
Dim X As String = Me.Location.X.ToString()
Dim Y As String = Me.Location.Y.ToString
Dim width As String = Me.Size.Width.ToString
Dim height As String = Me.Size.Height.ToString

' And your string variables are ready to be recorded into your
database.

...and when you want to apply them after retrieving from your
database, simply set these properties from db's in form's load event.


Thanks,

Onur Güzel
 
R

Rob Blackmore

You can construct a system.drawing.point from the x and y co-ordinates so
you could save them as either a single string or as two seperate fields. I
would save each as a seperate field as it would be easier to report upon.

However, if you want to store them as two strings (or one string) the code
below shows how to reconstruct the system.drawing.point from a comma
seperated string.

Kind regards,

Rob


Code follows:

Dim sLocation As String = ""

sLocation = Me.Location.X.ToString + "," + Me.Location.Y.ToString

Me.Location = New System.Drawing.Point(0, 0)
MsgBox("moved")

Me.Location = New System.Drawing.Point(Split(sLocation, ",")(0),
Split(sLocation, ",")(1))
MsgBox("moved back")
 
M

Marcolino

Hi,
Sure it's possible. Forms have "location" and "size" property and you
can get them as strings.

' Assign size/location of current form to strings
Dim X As String = Me.Location.X.ToString()
Dim Y As String = Me.Location.Y.ToString
Dim width As String = Me.Size.Width.ToString
Dim height As String = Me.Size.Height.ToString

' And your string variables are ready to be recorded into your
database.

...and when you want to apply them after retrieving from your
database, simply set these properties from db's in form's load event.

Thanks,

Onur Güzel

Thanks for your suggestion,
I know this way, but i need 4 field into Database, but in this case I
have only 2 fields, one for location and one for size.
My question is is there a way to put location into database using only
one field and then convert back.

Thanks
 
K

kimiraikkonen

Thanks for your suggestion,
I know this way, but i need 4 field into Database, but in this case I
have only 2 fields, one for location and one for size.
My question is is there a way to put location into database using only
one field and then convert back.

Thanks

Sorry if i misunderstood you, so you want to store location's X and Y
in a single string?

Then, would you mind concentrating size's height and width into one
string variable?

' To store
Dim location As String
location = "X:" & Me.Location.X & " " & "Y:" & Me.Location.Y


Thanks,

Onur Güzel
 
K

kimiraikkonen

Then, would you mind concentrating size's height and width into one
string variable?


Sorry for my mistype, i meant:
"Then, would you mind concentrating location's X and Y into one
string variable?"

..and it's clear what i meant from the code :)

Thanks,

Onur Güzel
 
M

Marcolino

You can construct a system.drawing.point from the x and y co-ordinates so
you could save them as either a single string or as two seperate fields.  I
would save each as a seperate field as it would be easier to report upon.

However, if you want to store them as two strings (or one string) the code
below shows how to reconstruct the system.drawing.point from a comma
seperated string.

Kind regards,

Rob

Code follows:

        Dim sLocation As String = ""

        sLocation = Me.Location.X.ToString + "," + Me.Location.Y..ToString

        Me.Location = New System.Drawing.Point(0, 0)
        MsgBox("moved")

        Me.Location = New System.Drawing.Point(Split(sLocation, ",")(0),
Split(sLocation, ",")(1))
        MsgBox("moved back")







- Mostra testo tra virgolette -

Hi Rob,
following your suggestion i created this 4 function that do excatly
what i need.
Bye

Public Function LocationToString(ByVal l As Point) As String
Trace("", "Location=" & l.ToString)
Return l.X.ToString & ";" & l.Y.ToString
End Function

Public Function LocationFromString(ByVal s As String) As Point
Trace("", "Location=" & s)
LocationFromString.X = Split(s, ";")(0)
LocationFromString.Y = Split(s, ";")(1)
End Function

Public Function SizeToString(ByVal s As Size) As String
Trace("", "Size=" & s.ToString)
Return s.Width.ToString & ";" & s.Height.ToString
End Function

Public Function SizeFromString(ByVal s As String) As Size
Trace("", "Size=" & s)
SizeFromString.Width = Split(s, ";")(0)
SizeFromString.Height = Split(s, ";")(1)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top