How to put objects [labels] within forms

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
atari800
Posts: 2
Joined: Thursday 30th June 2022 1:59pm

How to put objects [labels] within forms

Post 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
atari800
Posts: 2
Joined: Thursday 30th June 2022 1:59pm

Re: How to put objects [labels] within forms

Post 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
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How to put objects [labels] within forms

Post 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
If at first you don't succeed , try doing something differently.
BruceS
Post Reply