How to put objects [labels] within forms

Post

Posted
Rating:
#1 (In Topic #864)
Trainee
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

 ' 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
Online now: No Back to the top

Post

Posted
Rating:
#2
Trainee
I replaced this
 

Code

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

with this
 

Code

With Labelx = New Label(hForm[siCount]) As "Labelx"

Labels are showing up in forms
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
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..

Code (gambas)

  1.   For siCount = 0 To 7
  2.     With hForm[siCount] = New Form
  3.       .Name = "bForm"
  4.       .X = siCount * 50
  5.       .Y = siCount * 50
  6.       .W = 430
  7.       .H = 480
  8.       .Caption = "bCache " & Str(siCount) & " Form"
  9.       '.Show
  10.     End With
  11.     With Labelx = New Label(hForm[siCount]) As "Labelx" & Str(siCount)  ' this does the same as your Object.Attach() call.
  12.       .Y = 50
  13.       .X = 20
  14.       .W = 175
  15.       .H = 28
  16.       .Alignment = Align.Center
  17.       .Font.Bold = True
  18.       .Border = Border.Plain
  19.       .Text = "Test"
  20.     End With
  21.  
  22.   Next
  23.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.