A
A Nonymous
I created a PopUp edit based on a UserControl. It has a TextBox and a
button and works like a DateTimePicker except that in addition to date
and time, you can pick repeat intervals, days of the week, second
Tuesday, etc.
The problem is with the positioning of the PopUp. Basically the first
time I call PointToScreen I don't get the correct coordinates. The code
fragment I am using is shown below:
private void btnPick_Click(object sender, EventArgs e)
{
Point P = this.PointToScreen(Point.Empty);
if (P.Y + this.Height + editWhen.Height <=
SystemInformation.WorkingArea.Bottom)
P.Y += this.Height;
else
P.Y -= editWhen.Height;
editWhen.Location = P;
editWhen.Show();
}
What happens is the first time I click the drop down button the edit
window appears usually somewhere near the upper left corner of the
screen, but some times still on my app but near the upper corner of the
client area. The location is not completely consistent.
Now if I click the button again the dialog goes away, as designed, and
if I click it again it appears in the correct position. In fact from
then on I can just keep clicking on the button and it is always in the
correct location. I can even move the main form that contains my custom
edit and it is still correct.
It is only wrong, the first time I click the drop down button after the
form is created.
Any ideas on what is causing this, or how to fix it?
button and works like a DateTimePicker except that in addition to date
and time, you can pick repeat intervals, days of the week, second
Tuesday, etc.
The problem is with the positioning of the PopUp. Basically the first
time I call PointToScreen I don't get the correct coordinates. The code
fragment I am using is shown below:
private void btnPick_Click(object sender, EventArgs e)
{
Point P = this.PointToScreen(Point.Empty);
if (P.Y + this.Height + editWhen.Height <=
SystemInformation.WorkingArea.Bottom)
P.Y += this.Height;
else
P.Y -= editWhen.Height;
editWhen.Location = P;
editWhen.Show();
}
What happens is the first time I click the drop down button the edit
window appears usually somewhere near the upper left corner of the
screen, but some times still on my app but near the upper corner of the
client area. The location is not completely consistent.
Now if I click the button again the dialog goes away, as designed, and
if I click it again it appears in the correct position. In fact from
then on I can just keep clicking on the button and it is always in the
correct location. I can even move the main form that contains my custom
edit and it is still correct.
It is only wrong, the first time I click the drop down button after the
form is created.
Any ideas on what is causing this, or how to fix it?