المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Time Picker Problem*



C# Programming
08-23-2009, 06:51 PM
Hi, guys,
I am trying to get time by MouseDown and MouseUp events on a custom control with several picture boxes on it. Since e.X and e.Y can be taken when those two events occur, I create a method in that custom control called getTimeAt(int x, int y). The code of this method is as follows:
public DateTime getTimeAt(int x, int y)
{
DateTime selectedTime = new DateTime();
Random rnd=new Random();

int hour = (y - 10) / 20 + 7;
int minute = (x - 25) / 50 * 10+rnd.Next(1,9);

if (minute>59)
{
minute = 59;
}

selectedTime = DateTime.Today;
selectedTime = selectedTime.AddHours(hour);
selectedTime = selectedTime.AddMinutes(minute);



return selectedTime;
}
However, this doesn't work the same way as I expected. When I initiated one object of this custom control in a winform, and made a test app, do it as the following code,
private void selectorControl1_MouseDown(object sender, MouseEventArgs e)
{
maskedTextBox1.Text = selectorControl1.getTimeAt(e.X, e.Y).ToString("hhmm");
}it didn't get the e.X and e.Y from those picture boxes but only from that custom control. Anyone knows what's wrong here? Or does anybody have a better idea to solve my problem?
Thank you!