Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi how to add or create a label i

Status
Not open for further replies.

ahmed1973

Programmer
Jan 29, 2013
42
DZ
hi
how to add or create a label in a form progrmatically?
 
In the normal case you don't have the need to add controls at runtime.
But you can add any control via the form's AddObject() method...

Code:
thisform.Addobject("labelX","label")
thisform.labelX.top = 20
thisform.labelX.left = 30
thisform.labelX.caption ="test"
thisform.labelX.visible = .t.

Any object is created invisible, so you can position it and set it's visual style and caption etc. before showing it. This is really something you need to know. It's only mentioned sparsely. But it's mentioned in the help on Addobject:
Always watch out for passages in a hlpe topic in a special formatted box, eg with Caption "note". Those are mostly important notes. Als the whole "Remarks" section of help is having very important remarks.

Bye, Olaf.
 
PS: This code having all lines starting with THISFORM, needs to be in any form or form control method to work. You can also make use of Addobject from "outside" of the form, but you need a variable holding a form reference as it's value, then you can use that variable name instead of THISFORM. eg

Do form ...NAME loFORM LINKED
loForm.AddObject(...)
...

In this sepcific case, when you do this directly after the DO FORM or you would do it in the form init, you better do it in the form itself.

Also take note that in case you need a control or label sometimes and not other times, you can add it to the form and use it's visible property to hode or show it, you don't need to add it at runtime. And last not least it's preferable to use OOP, form classes you can inherit from. You can add a label or any amount of spcific controls to a child form class. You can even start with an empty base form, there are many things you can do in form methods you can recycle for any further form. Don't neglect the possibility to make use of inheritance and write once, use many times, just because you can't DO FORM a form class.

You can always have an SCX based on any form class and use it as usual. You only develop and extend your form classes and you use your SCXes. That's also a viable approach.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top