[Solved] Textbox set focus

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[Solved] Textbox set focus

Post by AndyGable »

Hi everyone,

Ok so this may be the stupidest question I have ever asked but I just wanted to make sure i am not going nuts

When my program starts i use
textbox1.setfocus


but I can not type inside it (i have to click on it with the mouse for the cursor to show up inside the text box


is there a way to make it so I can type with out having to click on it with the mouse?

I am sure I am missing a simple step here
Last edited by AndyGable on Tuesday 26th December 2023 2:12am, edited 1 time in total.
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Textbox set focus

Post by BruceSteers »

Works as expected here.

Your code must be giving something focus that you don't really want.
If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Textbox set focus

Post by AndyGable »

BruceSteers wrote: Monday 25th December 2023 7:12pm Works as expected here.

Your code must be giving something focus that you don't really want.
That is super strange

attached is my project so far could you see if it works your end if it does then it means there is something not right with my system (GTK3)

to test if you can type with out clicking then you can login with algpos for both user and password
Attachments
algPoSSupport.7z
(367.24 KiB) Downloaded 118 times
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Textbox set focus

Post by BruceSteers »

I'm not sure why it does not work, something to do with the form being loaded into a workspace.
After the workspace has Added the frmSignon it seems to give it focus.
I added this to the end of Main() in Startup.class

Print Application.ActiveControl

The result was frmSignon had focus not the textbox.

So I tried a few things then found if you change Form_Open() in frmSignon to Form_Show() then it works.
(I have often found Form_Open() to not work as expected when not opening a form the usual way but Form_Show() does)

The other option would be to make txtUserID Public and use frmSignon.txtUserID.SetFocus() at the end of Startup.class/Main()
If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Textbox set focus

Post by AndyGable »

BruceSteers wrote: Monday 25th December 2023 10:19pm I'm not sure why it does not work, something to do with the form being loaded into a workspace.
After the workspace has Added the frmSignon it seems to give it focus.
I added this to the end of Main() in Startup.class

Print Application.ActiveControl

The result was frmSignon had focus not the textbox.

So I tried a few things then found if you change Form_Open() in frmSignon to Form_Show() then it works.
(I have often found Form_Open() to not work as expected when not opening a form the usual way but Form_Show() does)

The other option would be to make txtUserID Public and use frmSignon.txtUserID.SetFocus() at the end of Startup.class/Main()
Thanks for looking but even when I changed the txtUserID to public and use frmSignon.txtUserID.SetFocus() at the end of Startup.class/Main()
it does not set focus to it. once I have clicked inside the textbox it works fine (lucky this is only for a internal support application I am designing) so I can put up with it for now
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Textbox set focus

Post by BruceSteers »

that is weird, it worked here just fine.
(although i had to comment out all the Connect calls)

what about the other fist more detailed method I said of changing frmSignon Form_Open() to Form_Show() rather than the additional alternative.

frmSignon.class
' Gambas class file

Public Sub Form_Show()

    btnClear_Click

End

If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Textbox set focus

Post by AndyGable »

Sorted.

I had to add a wait 0.1 to the btnClear_click function and it now sets the focus and allows me to type in the box :)
Post Reply