[Gambas-user] Public Form Controls

Demosthenes Koptsis demosthenesk at gmail.com
Sun Jul 23 21:56:35 CEST 2023


ok i understood the example you gave....


something else now but relative to subject...

Which programming approach is better... Public Form Controls OR Not 
Public...

As new programmer i feel more easier the Public Form Controls.

The example you gave increase complexity...



On 7/23/23 21:11, Bruce Steers wrote:
>
>
> On Sun, 23 Jul 2023 at 18:57, Bruce Steers <bsteers4 at gmail.com> wrote:
>
>
>
>     On Sun, 23 Jul 2023 at 18:11, Demosthenes Koptsis
>     <demosthenesk at gmail.com> wrote:
>
>         Hello,
>
>         is there a way to access a second form controls like
>         Form2.TextBox1 from
>         FMain without enable Public Form Control from options ?
>
>
>     Sure
>     you can use the Form[] _get method
>     Form2["TextBox1"]
>
>     that will return Control.class to properly acces TextBox.class do
>     this...
>
>     Dim tb As TextBox = Form2["TextBox1"]
>     tb.Text = "hello"
>
>
> Sorry that was too Brief.
>
> accessing Form2["TextBox1"] will return a "Control" object so you can 
> access any general control properties like Width, Background, Name etc.
>
> to access TextBox specific properties like Text, Placeholder etc use 
> the second method.
>
> or you can make a function to access any control type use Object
>
> Public Sub GetForm2Object(Name As String) As Object
>   Return Form2[Name]
>
> End
>
> Then something like this will work...
>
> GetForm2Object("TextBox1").Text = "This text"
>
> The plus side of using Object is it works for ANY control and it's 
> properties.
> the down side is the auto-complete only works if you specifically set 
> the object return type (Ie TextBox).
>
> Public Sub GetForm2TextBox(Name As String) As TextBox
>   if Form2[Name] Is TextBox Then Return Form2[Name]
> Error.Raise(Name & " is not a text box")
>
> End
>
> BruceS
>
>
> ----[http://gambaswiki.org/wiki/doc/netiquette  ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230723/193b9c52/attachment.htm>


More information about the User mailing list