Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Panel and KeyDown event problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marko Bozikovic - 07 Feb 2007 09:01 GMT
Hi all,

(I'm reposting this, original title was misleading)

I'm new to .NET, and I have a silly little problem. My application's layout is
simple: a window with one splitter with a treeview control in the left pane
and a Panel for rendering a DirectX scene in the right pane.

My problem is the KeyDown event. Before adding splitter and treeview,
everything worked fine - rendering panel received key events (I'm interested
in up/down/left/right/pageup/pagedown)

However, after I have added splitter and the treeview, my rendering panel
doesn't receive KeyDown events for up/down/left/right (they seem to be routed
to TreeView controls (render panel still receives pageup/pagedown events)

I'm aware of the focus problems with Panels, and I set main form's
ActiveControl to my render panel in panel's MouseDown event handler (actually,
this seems to set *splitter's* ActiveControl property, but it seems to be
working). The treeview control loses focus (as expected) and my render panel
handles pageup/pagedown keys. But, if I press one of up/down/left/right keys,
the treeview steals focus and responds to the key event.

I have even added a handler for PreviewKeyDown event in the rendering panel,
and it gets called for all keypresses, but I still don't know how to prevent
treeview from stealing focus.

Any ideas? (I'm using .NET 2.0)

Thank you,
Signature

Marko
ICQ: 5990814

I'm not under the alkafluence of inkahol
that some thinkle peep I am.
It's just the drunker I sit here the longer I get.

ClayB - 07 Feb 2007 11:00 GMT
Try overriding the form's ProcessDialogKey and catching the keystroke
there.

public partial class Form1 : Form
{
   public Form1()
   {
       InitializeComponent();
   }

   private void Form1_Load(object sender, EventArgs e)
   {
       this.ActiveControl = this.panel1;
       this.panel1.KeyDown += new KeyEventHandler(panel1_KeyDown);
   }

   void panel1_KeyDown(object sender, KeyEventArgs e)
   {
       ProcessKey(e.KeyCode);
   }

   public void ProcessKey(Keys keyCode)
   {
       this.Text = "handle " + keyCode.ToString() + " on panel";
   }

   protected override bool ProcessDialogKey(Keys keyData)
   {
       Keys keyCode = keyData & Keys.KeyCode;
       if (keyCode == Keys.Down || keyCode == Keys.Up
           || keyCode == Keys.Left || keyCode == Keys.Right)
       {
           ProcessKey(keyCode);
           return true;
       }
       return base.ProcessDialogKey(keyData);
   }
}

============
Clay Burch
Syncfusion, Inc.
Marko Bozikovic - 07 Feb 2007 13:15 GMT
> Try overriding the form's ProcessDialogKey and catching the keystroke
> there.
> -snip-

Thanks for the tip, but I think I have found a simpler solution. It seems that
it's enough to handle panel's PreviewKey event and set
PreviewKeyDownEventArgs.IsInputKey property to true for key's we're interested in.
Signature

Marko
ICQ: 5990814

I'm not under the alkafluence of inkahol
that some thinkle peep I am.
It's just the drunker I sit here the longer I get.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.