PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: buttons remain selected  (Read 496 times)

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
buttons remain selected
« on: July 30, 2018, 07:53: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.
Logged

José Roca

  • Guru Member
  • *****
  • Posts: 3171
Re: buttons remain selected
« Reply #1 on: July 30, 2018, 08:07: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>.
« Last Edit: July 30, 2018, 09:08:58 AM by José Roca »
Logged

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: buttons remain selected
« Reply #2 on: July 30, 2018, 08:50:29 AM »

thanks José Roca :), that fixed the problem.
I am new to GUI programming and was not aware of this detail.
Logged

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: buttons remain selected
« Reply #3 on: July 30, 2018, 09:05: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.
Logged

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: buttons remain selected
« Reply #5 on: July 30, 2018, 09:41: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)
« Last Edit: July 30, 2018, 09:58:10 AM by Johan Klassen »
Logged

José Roca

  • Guru Member
  • *****
  • Posts: 3171
Re: buttons remain selected
« Reply #6 on: July 30, 2018, 10:02: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.

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: buttons remain selected
« Reply #7 on: July 30, 2018, 10:14:35 AM »

thanks a million José Roca :)
ListBox_SetCurSel(Form1.ListBox1.hWindow, -1) did the trick :)
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8779
  • Windows 10
    • PlanetSquires Software
Re: buttons remain selected
« Reply #8 on: July 30, 2018, 01:35: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
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: buttons remain selected
« Reply #9 on: July 30, 2018, 02:10: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.
Logged