Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic OnKeyDown override required (Read 2101 times)
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
OnKeyDown override required
Dec 29th, 2010 at 6:09am
Print Post  
Hi Stoyo

I am inheriting my custom class from Diagram class to provide some default functionalities.

One of the functionality required is on pressing delete key should delete the nodes for that
overriding the "OnKeyDown" or "OnKeyUp" functions doesn't get triggered.

Also, providig the following code doesn't help.
       public override void OnApplyTemplate()
       {
           base.OnApplyTemplate();
           this.AddHandler(UIElement.KeyUpEvent, new KeyEventHandler(OnKeyUp), true);
       }

Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnKeyDown override required
Reply #1 - Dec 29th, 2010 at 12:12pm
Print Post  
Hi Rajesh,

Perhaps the diagram does not have the keyboard focus at that time. Try calling diagram.Focus() in response to MouseLeftButtonDown.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: OnKeyDown override required
Reply #2 - Jan 3rd, 2011 at 1:24pm
Print Post  
Hi Stoyo

Its not working. Focus is on diagram control.

What i did, selected the node and then pressed the delete key.

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnKeyDown override required
Reply #3 - Jan 4th, 2011 at 12:08pm
Print Post  
This works for me:

Code
Select All
public class DiagramEx : Diagram
{
	protected override void OnKeyUp(KeyEventArgs e)
	{
		base.OnKeyUp(e);
		if (e.Key == Key.Delete && ActiveItem != null)
			Items.Remove(ActiveItem);
	}

	protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
	{
		base.OnMouseLeftButtonUp(e);
		Focus();
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint