SRL Archive - OSR Help

ComboBox reacts on keypresses..


Chris

2012-08-30 02:39:20

FIXED :D
"OnKeyDown, ComboBox disable.. On Click, Combobox enable." -Brandon


I have this ComboBox in a form, with the options 'Easy', 'Normal' and 'Hard':
And when I click on one of the arrow keys:
The ComboBox's text changes. So when I have it like the above image and I press the down arrow key, it'll switch to 'Hard'.

How do I disable that? :D

A little vid to show it:
[youtube]zvA7oiv0t1Q[/youtube]

Sex

2012-08-30 02:57:59

That's normal bro. All comboboxes do that.

Chris

2012-08-30 04:48:57

But it's annoying.. Isn't there a way to make it only changable by clicking on it?
Or will I have to make a custom combobox? : /

VastlySuperior

2012-08-30 05:29:44

After changing The setting in the Combo Box, Take the focus away from the combo box. Problem solved.

Chris

2012-08-30 06:18:08

From: VastlySuperior
After changing The setting in the Combo Box, Take the focus away from the combo box. Problem solved.


Added a little vid to OP.

Daniel

2012-08-31 08:03:54

Unfortunately Chris, that is how the components of Windows (and pretty much all other) Forms work.

From: VastlySuperior
After changing The setting in the Combo Box, Take the focus away from the combo box. Problem solved.

That is really the only way you can do it.

Example:

mainForm.SetFocus;

Chris

2012-08-31 09:42:56

From: Daniel
Unfortunately Chris, that is how the components of Windows (and pretty much all other) Forms work.


That is really the only way you can do it.

Example:

mainForm.SetFocus;


I have tried this, but it doesn't fix it. (Probably because the combobox is on my mainform?) I used MainForm.SetFocus after every key press, but it's still changing..

Brandon

2012-08-31 09:52:29

OnKeyDown, ComboBox disable.. On Click, Combobox enable.

OR

Change the TabOrder of the combo box so that when the button is pressed, it will instead tab to the next component which should be the inner/main form.

OR

Capture the keypress for the combobox and do nothing in the event handler.


I'm not sure why they say all comboboxes do that. If it does then it's programmed badly. That shouldn't be default behaviour unless the combobox has focus and control. The tab button is supposed to be the only button that switches controls.. then pressing up and down will change options, but if tab isn't pressed, then that shouldn't happen. In this case, just override its events or disable it.

VastlySuperior

2012-08-31 10:33:58

I know to little about pascal to give you what you needed, but In VB6, it was all done by getfocus, setfocus, lostfocus, that`s why I said just shift the focus, but it seems to me that what Brandon suggest would work nicely and I take my hat off to him for knowledge about programming.

Chris

2012-08-31 14:17:31

From: Brandon
OnKeyDown, ComboBox disable.. On Click, Combobox enable.

OR

Change the TabOrder of the combo box so that when the button is pressed, it will instead tab to the next component which should be the inner/main form.

OR

Capture the keypress for the combobox and do nothing in the event handler.


I'm not sure why they say all comboboxes do that. If it does then it's programmed badly. That shouldn't be default behaviour unless the combobox has focus and control. The tab button is supposed to be the only button that switches controls.. then pressing up and down will change options, but if tab isn't pressed, then that shouldn't happen. In this case, just override its events or disable it.


"OnKeyDown, ComboBox disable.. On Click, Combobox enable." <– Works, thanks Brandon!

I've never had a look at the TabOrder and now have a bit of an idea, but still don't know what exactly it does..

I thought I had tried capturing the KeyPress event but I somehow used KeyDown, I should have slept instead of work on this program the morning after my birthday I guess :redface:

Also thanks to everyone else who thought about it and tried to help me. :D

mormonman

2012-08-31 15:18:24

You should have used a panel, or something that can take focus away from the combobox, for the gamescreen.

Chris

2012-08-31 17:33:16

From: mormonman
You should have used a panel, or something that can take focus away from the combobox, for the gamescreen.


Yes, that would have been easier.
Currently using TImages for the gamescreen, works pretty good though :D

Daniel

2012-08-31 23:31:36

From: Brandon
unless the combobox has focus and control.

Which it does :p

Strange that changing focus does not work, though..