+ 1
How to make a form which temporarily displays an image when a certain keystroke is typed? C#
I need to write a form that pops up an image when a determined keystroke is typed. It needs to open and close automatically for a short duration. Thanks in advance for any ideas.
2 Respostas
+ 1
I have writing some code to get you started. I assumed your are using winforms.
I used a keypress event to catch Keystroke and e.keychar to know which character was pressed
I created form2 to make something which is easily showable and hideable. On this form2 you can show your picture.
I added a timer to hide the form after a short duration.
public partial class Form1 : Form
{
Timer myTimer = new Timer();
Form2 form2 = new Form2();
void TimerEventProcessor(Object myObject,
EventArgs myEventArgs)
{
form2.Hide();
}
public Form1()
{
InitializeComponent();
myTimer.Interval = 5000;
myTimer.Tick += TimerEventProcessor;
form2.FormBorderStyle = FormBorderStyle.None;
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
myTimer.Start();
MessageBox.Show(e.KeyChar.ToString());
form2.Show();
}
+ 1
Thank you very much! I really appreciate you taking the time to get me started! I will work on this tonight when I return home!
And yes, you assumed correctly. Winforms