PlanetSquires Forums

Support Forums => PlanetSquires Software => Topic started by: Johan Klassen on July 30, 2018, 08:23:34 AM

Title: buttons remain selected
Post by: Johan Klassen on July 30, 2018, 08:23:34 AM
Hi Paul
in my simple calculator, the last button clicked remains selected, it's a problem because if you press the Return or Enter key it will activate that button again, this happens wether the Form KeyPreview is False or True.
however if I click on the Desktop for example and then click on my calculator then none of the buttons are selected, hope this makes sense.
Title: Re: buttons remain selected
Post by: José Roca on July 30, 2018, 08:37:19 AM
Normal. When a button is clicked it gains focus. Detect button clicks and change the focus to the main window with SetFocus <handle of the main window>.
Title: Re: buttons remain selected
Post by: Johan Klassen on July 30, 2018, 09:20:29 AM
thanks José Roca :), that fixed the problem.
I am new to GUI programming and was not aware of this detail.
Title: Re: buttons remain selected
Post by: Johan Klassen on July 30, 2018, 09:35:50 AM
on a related subject, is there a way to un-select an item in a ListBox?
because once an item is selected it remains selected until a different item is selected, I would like for none to be selected.
Title: Re: buttons remain selected
Post by: José Roca on July 30, 2018, 09:45:29 AM
See: https://docs.microsoft.com/en-us/windows/desktop/api/Windowsx/nf-windowsx-listbox_setcursel
Title: Re: buttons remain selected
Post by: Johan Klassen on July 30, 2018, 10:11:32 AM
I am afraid that I need more help, I tried the following but I get a "Type mismatch, at parameter 1 of SNDMSG()"
ListBox_SetCurSel(Form1.ListBox1, Form1.ListBox1.SelectedItem)

the following compiles but completely destroys the contents of the ListBox
ListBox_SetCurSel(Form1.ListBox1.SelectedItem.Text, -1)
Title: Re: buttons remain selected
Post by: José Roca on July 30, 2018, 10:32:00 AM
The zero-based index of the item to select, or â€"1 to clear the selection.

ListBox_SetCurSel(Form1.ListBox1, -1)

If Form1.ListBox1 gives you a type mismatch error, the ask Paul. Maybe you have to use Form1.ListBox1.hWindow or something like that.

Title: Re: buttons remain selected
Post by: Johan Klassen on July 30, 2018, 10:44:35 AM
thanks a million José Roca :)
ListBox_SetCurSel(Form1.ListBox1.hWindow, -1) did the trick :)
Title: Re: buttons remain selected
Post by: Paul Squires on July 30, 2018, 02:05:36 PM
Be careful with the ListBox because it is a work in progress at this point. Your approach to send ListBox*.* macro messages to the hWindow property should work without any issues but there are other things in the ListBox that need to be completed before the ListBox control can be considered feature complete.

In your case, do you even want any line in the ListBox to ever be selected/highlighted? If you do not, then you can simply set the ListBox's SelectionMode property at design time to ListSelectionMode.None
Title: Re: buttons remain selected
Post by: Johan Klassen on July 30, 2018, 02:40:49 PM
Hi Paul
for my calculator I don't want any items to be selectable, your suggestion of setting the ListBox property to ListSelectionMode.None works as advertised, however I don't mind learning a trick now and then.