Created
March 28, 2011 10:45
-
-
Save turugina/890267 to your computer and use it in GitHub Desktop.
test script for detecting KeyDown event for arrow keys on MdiChild Form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System | |
import System.Windows.Forms; | |
class Parent(Form): | |
public def constructor(): | |
self.IsMdiContainer = true | |
_btn = Button(Text: "Create Child") | |
_btn.Click += self.CreateChild | |
self.Controls.Add(_btn) | |
_btn as Button | |
_i = 0 | |
private def CreateChild(): | |
c = Child(Text: "child$_i", MdiParent: self) | |
c.Show() | |
++_i | |
class Child(Form): | |
public def constructor(): | |
_lbl = Label(Text: "TEST") | |
_lbl.Dock = DockStyle.Bottom | |
_lbl2 = Label(Text: "TEST2") | |
_lbl2.Dock = DockStyle.Bottom | |
_lbl3 = Label(Text: "TEST3") | |
_lbl3.Dock = DockStyle.Bottom | |
self.Controls.Add(_lbl) | |
self.Controls.Add(_lbl2) | |
self.Controls.Add(_lbl3) | |
self.KeyDown += {o,e|_lbl.Text = "kd: $o: ${e.KeyCode}"} | |
self.Load += self.OnLoad | |
_lbl as Label | |
_lbl2 as Label | |
_lbl3 as Label | |
private def OnLoad(sender, e): | |
self.MdiParent.PreviewKeyDown += self.OnParentPreviewKeyDown // * 1. | |
self.PreviewKeyDown += self.OnPreviewKeyDown | |
// * 1. MDI親WindowのPreviewKeyDownにつなげても呼び出されない | |
private def OnParentPreviewKeyDown(sender, e as PreviewKeyDownEventArgs): | |
_lbl2.Text = "pkd(p): ${sender}: ${e.KeyCode}" | |
if e.KeyCode == Keys.Right or e.KeyCode == Keys.Left: | |
e.IsInputKey = true | |
private def OnPreviewKeyDown(sender, e as PreviewKeyDownEventArgs): | |
_lbl3.Text = "pkd(c): ${sender}: ${e.KeyCode}" | |
if e.KeyCode == Keys.Right or e.KeyCode == Keys.Left: | |
// IsInputKey が true であれば KeyDown eventが発生する | |
e.IsInputKey = true | |
[STAThread] | |
public def Main(argv as (string)) as void: | |
Application.EnableVisualStyles() | |
Application.SetCompatibleTextRenderingDefault(false) | |
Application.Run(Parent(Text: "parent")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment