[Gambas-user] Custom controls - 1 more question

Doriano Blengino doriano.blengino at ...1909...
Tue Jan 19 13:23:02 CET 2010


I wrote:
> He does not need - at the time of the label creation with NEW, lblName 
> gets two references; one of them is discarded by leaving the subroutine, 
> but the other, held by the form (thanks to "(ME)"), remains; so the 
> label is not destroyed. Kadaitcha is right - the label should have 
> something to display, and show() does nothing because the Visible 
> property is already true by default. Or, at least, so It should be - too 
> lazy to try by myself...
>   

Kadaitcha Man wrote:
> 2010/1/19 Ron_1st <ronstk at ...239...>:
>
>   
>> if he want the control always on the form the dim must be done global
>> in the head else it lives only for the time the subroutine lives (??)
>>     
>
> Wrong. His code will show nothing. The default background of a label
> is the same as that of a form. A label has no border, and his code
> does not apply a caption to the object either. Therefore the result is
> an object in a certain shade grey on a form of the very same shade of
> grey. The visible result is zilch, nada, nothing, nowt, nought, blank,
> not anything, zip, emptiness, nonexistence.
>
> Capice?
>
> That said, when the nothingness problem is fixed, gambas still does
> not display the label correctly because it has been put, by default,
> in a non-displayable area of the window, i.e. under the title bar at
> 0,0, and not in the displayable area of the window.
>
> There is a bug, IMO, but not where you or the OP mistakenly believes
> it to be. 0,0 seems to be the top left corner of the whole window,
> including the title bar. It does not seem that 0,0 is within the
> visible boundary of the window _below_ the title bar.
>   
Made some experiment. It turned out that a label starts with no text 
(so, nothing to display), and x=y=width=height=0.
To create a visible label one must set the text, and either set width 
and height, or set autosize to true.
The instruction to set Autosize can be before or after the one that sets 
the text. I think that setting autosize after having set the text should 
do nothing - until the text changes again. But this is debatable and of 
little importance.
On my gambas (2.0.0), X and Y are correct - they are relative to the 
*clientarea* of the form - omitting to set them show a label in the 
upper-left corner.
My experiment also confirms that there is no need to use global 
variables. In the form_open() I wrote:

  DIM l AS Label

  l = NEW Label(ME)
  l.Text = "Ciao"
  ' l.AutoResize = TRUE   ' alternative: use this and omit width+height
  l.Width = 50
  l.Height = 20

and it works flawlessly. Just for /strictly/ speaking, one can omit to 
set the text - it is possible to set backcolor, width and height, to 
have an empty but visible label (in this case, Autoresize does not work 
:-)).

In respect to my style, I am too lazy to further look about what 
Kadaitcha says (wrong X and Y). On gambas 2.0.0 they are correct, and I 
strongly suspect that more recent versions of gambas are correct too 
(but who knows).
BTW: it seems to me that gambas 2.0.0, among all the versions I tried, 
is the smoothest one.

Regards,
Doriano




More information about the User mailing list