Page 1 of 1

How to put objects [labels] within forms

Posted: Thursday 30th June 2022 2:48pm
by atari800
I am creating forms dynamically and want to place objects (labels, buttons, etc) in them
I have no problem creating the forms, it is attaching/inserting objects

Code: Select all

 ' create forms
  hForm = New Object[8] 
  For siCount = 0 To 7
    With hForm[siCount] = New Form
      .Name = "bForm"
      .X = siCount * 50
      .Y = siCount * 50
      .W = 430
      .H = 480
      .Caption = "bCache " & Str(siCount) & " Form"
      '.Show
    End With
    With Labelx = New Label(Me) As "Labelx"
      .Y = 50
      .X = 20
      .W = 175
      .H = 28
      .Alignment = Align.Center
      .Font.Bold = True
      .Border = Border.Plain
      .Text = "Test"
    End With
    Object.Attach(Labelx, hForm[siCount], "Labelx" & Str(siCount))
  Next
If I can get an example of placing 2 labels in a form, I would be much appreciative

Thank you in advance

Re: How to put objects [labels] within forms

Posted: Thursday 30th June 2022 7:07pm
by atari800
I replaced this

Code: Select all

With Labelx = New Label(me) As "Labelx"
with this

Code: Select all

With Labelx = New Label(hForm[siCount]) As "Labelx"
Labels are showing up in forms

Re: How to put objects [labels] within forms

Posted: Thursday 30th June 2022 7:43pm
by BruceSteers
Yes Me refers to the class the function is in not the newly created forms. you fixed that okay yourself

BTW. you should ditch either using As "labelx" in the form creation or using the Object.Attach() call as they both do the same thing.
Eg..
  For siCount = 0 To 7
    With hForm[siCount] = New Form
      .Name = "bForm"
      .X = siCount * 50
      .Y = siCount * 50
      .W = 430
      .H = 480
      .Caption = "bCache " & Str(siCount) & " Form"
      '.Show
    End With
    With Labelx = New Label(hForm[siCount]) As "Labelx" & Str(siCount)  ' this does the same as your Object.Attach() call.
      .Y = 50
      .X = 20
      .W = 175
      .H = 28
      .Alignment = Align.Center
      .Font.Bold = True
      .Border = Border.Plain
      .Text = "Test"
    End With

  Next