Thats what my problem is.I Set the button's left as form's left and button's top+buttons'height as form's top. This is the logic.
protected override void OnClick(EventArgs e) { SetAutoLocation(); frmCal.Show(); Invalidate(); } private void SetAutoLocation() { Rect rect; GetWindowRect(this.Handle, out rect); Point tergatePoint; tergatePoint = new Point(rect.left, rect.top + this.Height); tergatePoint = new Point(Left, Top + Height); if (rect.left + this.Width - frmCal.Width < 0) { tergatePoint.X = 0; } else { tergatePoint.X = rect.left - frmCal.Width + this.Width; } if (tergatePoint.X + frmCal.Width > System.Windows.Forms.SystemInformation.WorkingArea.Right) { tergatePoint.X = System.Windows.Forms.SystemInformation.WorkingArea.Right - frmCal.Width; } else if (tergatePoint.X < 0) tergatePoint.X = 0; if (tergatePoint.Y + frmCal.Height > System.Windows.Forms.SystemInformation.WorkingArea.Bottom) { tergatePoint.Y = rect.top - frmCal.Height; } if (tergatePoint.Y < 0) { tergatePoint.Y = 0; } if (tergatePoint.X < 0) { tergatePoint.X = 0; } frmCal.Location = tergatePoint; } public struct Rect { internal int left, top, right, bottom; }
First click form is not positioning well ,but from second click onwards it is working fine. Can you just see that logic is correct or not?
M.Sendilkumar