32
of 76
TEP , The Engineering Projects , Image

syedzainnasir

TEP , The Engineering Projects , Rating 7.5 7.5 / 10
TEP , The Engineering Projects , Icon Level: Moderator
TEP , The Engineering Projects , Icon Joined: 20 Mar 2022
TEP , The Engineering Projects , Icon Last Active: 2:21 PM
TEP , The Engineering Projects , Icon Location: TEP , The Engineering Projects , Flag
TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon
Trapping Key presses in C# Child form
TEP , The Engineering Projects , Calender Question: 07-Mar-2017
TEP , The Engineering Projects , Category In: Microsoft Visual Studio Projects
I have seen several posts about trapping keys presses but none specific to child forms. In the code fragments below Key presses are trapped when the focus is the parent form but not when the focus is the child form. What else do I need to do to trap those also? I would also like to be able to trap arrow keys in the child form if possible. Unrelated code deleted. [code]public partial class Main : Form { private void btGraph_Click(object sender, EventArgs e) { Graph WaveGraph = new Graph("Waveform"); other code placing graphics on the form } // need to trap arrow keys. protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Up) { MessageBox.Show("Up key pressed"); return true; } return base.ProcessCmdKey(ref msg, keyData); } } class Graph { public Graph(string name) { GraphForm = new Form(); GraphForm.Name = name; GraphForm.KeyPress += new KeyPressEventHandler(OnKeyPress); GraphForm.KeyPreview = true; } // The message box never appears private void OnKeyPress(object sender, KeyPressEventArgs e) { string KeyString = e.KeyChar.ToString(); MessageBox.Show("A key was pressed"); return; } }[/code]
TEP , The Engineering Projects , Icon Answer: 0 TEP , The Engineering Projects , Icon Views: 150 TEP , The Engineering Projects , Icon Followers: 85
Small Bio
TEP , The Engineering Projects , Tags
PLC
Robot
STM32
Arduino
AI
ESP32
Ladder Logic
PLC Projects
Programming
Communicates STM32
PLC Projects
Communicates PLC
Font Style
Alignment
Indenting and Lists
Insert Media
Insert Items

Want to leave an answer!

Word Count :0 Draft Saved at 12:42 am.