[Gambas-user] User Controls and Font resizing to fit content

Gianluigi bagonergi at gmail.com
Tue May 1 16:19:34 CEST 2018


2018-05-01 15:16 GMT+02:00 Tobias Boege <taboege at gmail.com>:

> On Tue, 01 May 2018, KKing wrote:
> > Sorry to repeat and if any is covered by wiki/doco but I didn't seem to
> find
> > any recent info on easily.
> >
> > 1. Does Gambas have a concept similar to the VB User Control concept
> > (i.e. you build a control with the standard label/textbox/buttons save
> > it and be able to reuse multiple times in another form)?
> >
>
> I put an answer off the first time around, because this question actually
> needs a whole tutorial to be answered.
>
> I don't know VB but Gambas does have a UserControl class for creating
> custom controls. This is usually a two-step process:
>
>   1. Create a form FMyControl and use the form editor to place your
>      Labels, Buttons and everything else, then write their functionality
>      into FMyControl's code.
>
>   2. Create a class MyControl which inherits UserControl. This class
>      will create an instance of FMyControl and embed it into itself.
>      This way, you get the widget FMyControl but don't inherit all the
>      methods and properties of the Form class. You will have to proxy
>      the interface parts of FMyControl which you do want to expose
>      yourself.
>
> This technique is used in Gambas a lot. You should look through the
> source code of gb.form for examples, or ask followup questions.
>
> The ListEditor [1] is a very good starting point, because it is small,
> easy to read and does only the things mentioned above. You will find
> some UserControls without a corresponding form; these build their
> appearance by code only, without the help of the form editor.
> This makes sense for ValueBox, for example, which switches between
> multiple input controls.
>
> A tutorial for this would be nice to have, along with how to use
> Arrangement, Expand, Spacing and Margin -- something like
> "Advanced GUI techniques" -- does the Gambas magazine still exist? :-)
>
> > 2. Suggestions if convenient way to get the font size to automatically
> > change to fit provided text in a (can be any of) label/textbox/or other
> > control?
> >
>
> I don't know. Something like that would be nice for translated projects,
> where you can't estimate the content size of a Label at development time.
> [ Not sure if reducing the font size or enlarging the label is the right
> way
> to go, but I guess anything but cutting off excessive text can go horribly
> wrong. ]
>
> Regards,
> Tobi
>
> [1] https://gitlab.com/gambas/gambas/tree/master/comp/src/
> gb.form/.src/ListEditor
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
>
You have to forget about VB, Gambas is different, it's better and with a
few clicks you create windows that do everything you want.
You have to understand the containers, you have to study the IDE as Tobias
advised you.

See small attached example, look at the properties of the controls

Regards
Gianluigi


> --------------------------------------------------
>
> This is the Gambas Mailing List:
> https://lists.gambas-basic.org/listinfo/user
>
> Search the list:
> https://lists.gambas-basic.org/cgi-bin/search.cgi
>
> Hosted by https://www.hostsharing.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180501/5a7798a0/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QTExample-0.0.1.tar.gz
Type: application/gzip
Size: 11507 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180501/5a7798a0/attachment-0001.gz>


More information about the User mailing list