Metro Set Ui Key Events dont work
am trying to create a simple program using windows forms C# and have a text box and a list... i can add text to the list using another button but when i try to add text using the keypress event it just dings and nothing happens
33 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
BlazeBin - ciohcrupjgkk
A tool for sharing your source code with the world!
my input is a keypress <Enter> in the text box and i expect it to fill the list with what ever content the text box has
but this isnt happening and i just hear a ding sound once i press the key
Have you tried debugging to see what's actually happening?
there is no error whatsoever
Right, but debug to see if it's actually hitting that event handler at all
Set a breakpoint, run your app, press enter in the textbox
nope it dosent hit the event handler
Have you checked the properties of your textbox to see if the event handler for KeyDown is set correctly?
yes
key preview is true
So you're handling it in a different event handler?
no its in the same event handler
or i dint get what u were tryna say
well you'd set keypreview = true if you want the key press event to be handled by your Form rather than by the specific control
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.keypreview?view=windowsdesktop-8.0
So I assumed you mentioned that because you were handling the keydown event in some other event handler...
yea i want it to be handled by the form but if u mean handling by the form is not same as being handled by the text box in the form i think its better off
no no i want the key event handler just for the text box
Right, so you don't need to set KeyPreview = true then?
is that a question? T_T
Sort of, unless you've got it set because of some other reason I don't think you need it set
no no i just set it true for this purpose
i dont need it for anything else
Then you don't need it set
ok
i set it true cuz some forums said it helps
If there's a reason to set it, like you want to handle key press events at a form level first, then go on to the specific control event handler then sure
Are you still seeing the issue after removing that?
it was already removed previously and i still had the issue.. turning it on dint have any effecct
also am using a metro set ui
can this be the reason?
Shouldn't be
In your textbox properties, is the KeyDown event handler properly set?
yea
it is set
Saying that, someone did log this:
https://github.com/N-a-r-w-i-n/MetroSet-UI/issues/44
GitHub
MetroTextBox not react to keys · Issue #44 · N-a-r-w-i-n/MetroSet-UI
Don't work with _keydown, for "Enter" keycode at leat.
Maybe just try it with a normal winforms textbox and see if that works
i could but i already built my program using metroset ui T_T
For the sake of proving the point it will only take you a minute to try it
ai8 lemme make one quick
yea it workes in a normal form
@SinFluxx
I mean the easiest way might be to move it to the KeyUp event instead?
i tried all three
I mean that issue I linked above was logged 2021, and from a glance there haven't been any updates to the repo in 4 years, so it may just be an issue you're stuck with unless someone knows some way around it