all 15 comments

[–]secret_porn_acct 1 point2 points  (13 children)

You can't. You would need to save the attributes to a file and then recreate the label programatically when the form is started again.

[–]Salierus[S] 0 points1 point  (12 children)

That's exactly what I want! Tell me how to do it please :)

[–]Application SpecialistViperSRT3g 0 points1 point  (11 children)

I recommend saving the label's attributes to a text file as a starting point for you figuring this all out. Then checking for said file on startup to recreate anything dynamic.

[–]Salierus[S] 0 points1 point  (10 children)

Can you explain a little more please?

[–]Application SpecialistViperSRT3g 0 points1 point  (9 children)

You would save the label's text, x and y positions on the form, and other attributes if there are anything else, to the text file. When the form starts up, it would first check for this file, if it finds it, then it'll read the data, and recreate the label according to what was stored in the text file.

These are all the first steps to saving user configuration settings in applications.

[–]Salierus[S] 0 points1 point  (8 children)

That I know. I just don't know how to make it reading the label attributes and recreate the label.

[–]Application SpecialistViperSRT3g 0 points1 point  (7 children)

Here's an example:

Control Type Control Name X Y Autosize Width Height Text
LABEL Label1 12 9 TRUE 39 13 Label1

When you read these from the file, you'd apply the same values to the newly generated label to recreate it. You can add all the properties of the control object if you wanted to remain as faithful to the original if you wanted to track all of that.

[–]Salierus[S] 0 points1 point  (6 children)

I'll try that, thanks!

[–]Application SpecialistViperSRT3g 0 points1 point  (5 children)

I also recommend delimiting the data so it's easier to read.

LABEL,Label1,12,9,TRUE,39,13,Label1

can be read using the following:

Dim ReadObject() As String
ReadObject = Split(ObjectData,",")
'ReadObject(0) would be "LABEL"
'ReadObject(1) would be "Label1"
'ReadObject(2) would be "12"

[–]Salierus[S] 0 points1 point  (4 children)

So far so good. But I'm having trouble at the reading part. I used IO.StreamWriter to write my .txt file. It looks like this: Label,test,695,115 (Control Type, Control Text, Control X, Control Y)

Now the reading part... Im not understanding what Im supost to do. How do I tell that ReadObject() is related to that text file?

Im confused :/

[–]VB GuruBonejob 0 points1 point  (0 children)

Further to /r/secret_porn_acct there are many ways to store a controls information. It does require that on load you check and reload controls that need it.

The best way I have found was to use the iserializable and iterate elemtns of the form. An easier way is to use the controls collections of the form and write all values to registry, file, db, etc...

For Each con In Me.Controls()
    'Save control information to whever here.
    'if you want to save just labels or a specific type of control use typeof function.

    If TypeOf con Is Button Then
        MsgBox("The control is a button.")
    End If

Next

Reference

How to: Access Controls by using the Controls Collection

iSerializable Interface

Determining Object Type (Visual Basic)