It's just a function name, so it shouldn't matter.
Here's the full code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using System.Net;
using Routrek.SSHC;
using Routrek.SSHCV2;
namespace ComicViewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.KeyUp += new KeyEventHandler(this.ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Left)
MessageBox.Show("Left arrow key");
else if (e.KeyData == Keys.Right)
MessageBox.Show("Right arrow key");
}
DateTime curdate = new DateTime(1978, 06, 19);
DateTime begindate;
int totaldays = 0;
private void Form1_Load(object sender, EventArgs e)
{
loadImage(curdate);
setDate();
// Populate progressbar
TimeSpan numdays = DateTime.Now - curdate;
totaldays = numdays.Days;
begindate = curdate;
progressBar1.Maximum = numdays.Days;
progressBar1.Minimum = 0;
setProgressBar();
}
public void setDate()
{
textBox1.Text = curdate.Year.ToString();
textBox2.Text = curdate.Month.ToString();
textBox3.Text = curdate.Day.ToString();
}
public void setProgressBar()
{
TimeSpan span = curdate - begindate;
progressBar1.Value = span.Days;
toolTip1.SetToolTip(progressBar1, "Comic " + span.Days +
"/" + totaldays);
}
public string formatDate(DateTime time)
{
string year = curdate.Year.ToString();
year = year.Substring(year.Length - 2);
string month = curdate.Month.ToString().PadLeft(2, '0');
string day = curdate.Day.ToString().PadLeft(2, '0');
return year + month + day;
}
public void loadImage(DateTime time)
{
try
{
HttpWebRequest req =
(HttpWebRequest)HttpWebRequest.Create("http://192.168.1.12/garfield/garfield_coll/ga"
+ formatDate(time) + ".gif");
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
pictureBox1.Image =
Image.FromStream(res.GetResponseStream());
}
catch (Exception e)
{
button1_Click(new object(), new EventArgs());
}
}
private void button2_Click(object sender, EventArgs e)
{
curdate = curdate.AddDays(1);
progressBar1.Value += 1;
loadImage(curdate);
setDate();
setProgressBar();
}
private void button1_Click(object sender, EventArgs e)
{
curdate = curdate.AddDays(-1);
progressBar1.Value -= 1;
loadImage(curdate);
setDate();
setProgressBar();
}
private void button3_Click(object sender, EventArgs e)
{
curdate = DateTime.Parse(textBox1.Text + "/" +
textBox2.Text + "/" + textBox3.Text);
loadImage(curdate);
setDate();
setProgressBar();
}
private void button4_Click(object sender, EventArgs e)
{
using (showLink frm = new showLink())
{
frm.textBox1.Text =
"http://images.ucomics.com/comics/ga/" + curdate.Year + "/ga" +
formatDate(curdate) + ".gif";
frm.textBox1.Update();
frm.ShowDialog();
}
}
}
}
Gugale at Lincoln wrote:
Have you renamed the form to ActiveForm? Can you post the entire code?
SG
"Ben" <el*****@gmail.comwrote in message
news:ek**************@TK2MSFTNGP06.phx.gbl...
>Gugale at Lincoln wrote:
>>Use KeyData I tried following code and it works.
SG
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form2_Ke yUp);
}
private void Form2_KeyUp(object sender, KeyEventArgs e)
{
Console.WriteLine(e.KeyData == Keys.Left);
}
}
"Ben" <el*****@gmail.comwrote in message
news:OU**************@TK2MSFTNGP06.phx.gbl...
Gugale at Lincoln wrote:
May be the event is not reaching the form? Do you get the same problem
when you have an empty form without any child controls?
>
SG
>
"Ben" <el*****@gmail.comwrote in message
news:ud**************@TK2MSFTNGP06.phx.gbl.. .
>Hello,
>>
>I'm trying to catch the pressing of the left and right arrow keys
>through the KeyUp event, like so:
>>
>public Form1()
> {
> InitializeComponent();
> Form1.ActiveForm.KeyUp += new
>KeyEventHandler(ActiveForm_KeyUp);
> }
>>
>void ActiveForm_KeyUp(object sender, KeyEventArgs e)
> {
> if (e.KeyCode == Keys.Left)
> MessageBox.Show("Left arrow key");
> else if(e.KeyCode == Keys.Right)
> MessageBox.Show("Right arrow key");
> }
>>
>Yet the event is never called when I press a button. I tried putting
>the event binding in the form load, but that didn't work either.
>>
>Any ideas?
>>
>Thanks,
>Ben
That doesn't work either. I created a whole new project with just an
empty form using about the same code and no luck.
I just tried that, like so:
public Form1()
{
InitializeComponent();
this.KeyUp += new KeyEventHandler(this.ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Left)
MessageBox.Show("Left arrow key");
else if (e.KeyData == Keys.Right)
MessageBox.Show("Right arrow key");
}
But still no luck.
Odd.