FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RichTextBox problem

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
maxter



Joined: 17 May 2006
Posts: 34

PostPosted: Wed May 17, 2006 1:50 pm    Post subject: RichTextBox problem Reply with quote

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
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Wed May 17, 2006 7:48 pm    Post subject: Re: RichTextBox problem Reply with quote

New snapshot appears to handle it correctly. Thanks for letting me know about this.
- Chris
Back to top
View user's profile Send private message
asterite



Joined: 01 Jun 2006
Posts: 235
Location: Buenos Aires, Argentina

PostPosted: Fri Jun 16, 2006 8:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger MSN Messenger
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Sat Jun 17, 2006 8:12 am    Post subject: Reply with quote

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
View user's profile Send private message
asterite



Joined: 01 Jun 2006
Posts: 235
Location: Buenos Aires, Argentina

PostPosted: Sat Jun 17, 2006 10:40 am    Post subject: Reply with quote

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 Very Happy)

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
View user's profile Send private message Yahoo Messenger MSN Messenger
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Mon Jun 19, 2006 11:44 am    Post subject: Reply with quote

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
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Jun 22, 2006 9:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
asterite



Joined: 01 Jun 2006
Posts: 235
Location: Buenos Aires, Argentina

PostPosted: Thu Jun 29, 2006 8:43 pm    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger MSN Messenger
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Jun 29, 2006 10:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group