View previous topic :: View next topic |
Author |
Message |
maxter
Joined: 17 May 2006 Posts: 34
|
Posted: Wed May 17, 2006 1:50 pm Post subject: RichTextBox problem |
|
|
I'm trying to filter out a key down message for a RichTextBox the way that worked in Win Forms
Code: |
override onKeyDown(KeyEventArgs e)
{
if(e.keyCode == Keys.ENTER)
{
e.handled = true;
}
}
|
this doesn't seem to work in DFL. Is there a workaround for the problem? |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Wed May 17, 2006 7:48 pm Post subject: Re: RichTextBox problem |
|
|
New snapshot appears to handle it correctly. Thanks for letting me know about this.
- Chris |
|
Back to top |
|
|
asterite
Joined: 01 Jun 2006 Posts: 235 Location: Buenos Aires, Argentina
|
Posted: Fri Jun 16, 2006 8:51 pm Post subject: |
|
|
Is this problem solved?
I downloaded the last snapshot of DFL and I can see that the key-related events are not sent for the ENTER key. I mean:
Code: |
someControl.keyDown ~= &someControl_keyDown;
// Somewhere after...
private void someControl_keyDown(Object object, KeyEventArgs kea) {
// If the user pressed enter, nothing here gets executed
}
|
Can someone test this?
Thanks,
Ary |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Sat Jun 17, 2006 8:12 am Post subject: |
|
|
Code: | import dfl.all;
import std.stdio;
class MyForm: Form
{
RichTextBox rtb;
this()
{
with(rtb = new RichTextBox)
{
keyDown ~= &someControl_keyDown;
rtb.parent = this;
}
}
private void someControl_keyDown(Object object, KeyEventArgs kea)
{
if(kea.keyCode == Keys.ENTER)
{
writefln("ENTER pressed!");
}
}
}
int main()
{
Application.run(new MyForm);
return 0;
} |
Compiled as a console exe and "ENTER pressed!" is echoed just fine for me. |
|
Back to top |
|
|
asterite
Joined: 01 Jun 2006 Posts: 235 Location: Buenos Aires, Argentina
|
Posted: Sat Jun 17, 2006 10:40 am Post subject: |
|
|
Sorry, I've made a mistake, I'm talking about a plain TextBox. There's where you don't recieve the event is ENTER was pressed (I realized this yesterday at night, but I was already in my warm bed... it's winter here )
Code: |
import dfl.all;
import std.stdio;
class MyForm: Form
{
TextBox tb;
this()
{
with(tb = new TextBox)
{
keyDown ~= &someControl_keyDown;
parent = this;
}
}
private void someControl_keyDown(Object object, KeyEventArgs kea)
{
if(kea.keyCode == Keys.ENTER)
{
writefln("ENTER pressed!");
} else {
writefln("Something!");
}
}
}
int main()
{
Application.run(new MyForm);
return 0;
}
|
You can see "Something!" is printted if a key is pressed, but nonthing is printed in the key enter. I must have this functionality as a short-cut to send some text instead of pressing a send button. |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Mon Jun 19, 2006 11:44 am Post subject: |
|
|
Perhaps all you need to do is set the Form's acceptButton property, which gets "clicked" when the user presses enter on a control that does not process the enter key. It can be set to a Button or a class that implements the IButtonControl interface.
However, what you reported about TextBox and it not receiving the enter key is a real issue that I'm working on. Thanks for letting me know about this.
- Chris |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Thu Jun 22, 2006 9:45 pm Post subject: |
|
|
Current snapshot lets you handle enter key events for TextBox, but you should still consider Form.acceptButton as it also works if other controls are focused. |
|
Back to top |
|
|
asterite
Joined: 01 Jun 2006 Posts: 235 Location: Buenos Aires, Argentina
|
Posted: Thu Jun 29, 2006 8:43 pm Post subject: |
|
|
I guess I understand now why the ENTER key wasn't sent in the event. Check the begginer application (begginer.d) in the DFL examples. Compile it, open it and try to enter some lines as comments: you can't, the Vote button is pressed instead.
It seems the acceptButton has more priority than the ENTER button in the textbox.
(maybe you had this problem before and changed it so that the ENTER is passed through to get a new line... and that's why the previous code I sent didn't word... but that's just a guess).
So what's the solution for this? How is this implemented in .Net for example? |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Thu Jun 29, 2006 10:33 pm Post subject: |
|
|
asterite wrote: | It seems the acceptButton has more priority than the ENTER button in the textbox. |
It depends on if the TextBox has acceptsReturn = true; and which snapshot you have; newest one should do it right. |
|
Back to top |
|
|
|