Heiko Posted March 13, 2003 Posted March 13, 2003 I have a custom DateTimePicker Control. This control will - upon clicking a buttom - show a MonthCalendar. As I can not resize the usercontrol I need to show the calendar on an extra form. Much to my embarrasment, I can not figure out, how to have this extra form position exactly at that position where the button was clicked (upper left corner == mouse.position). Here's my pathetic attempt ... Private Sub btnCalendar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnCalendar.MouseDown mLoc = Nothing 'mLoc is a private variable in my class mLoc = New Point(e.X, e.Y) End Sub Private Sub btnCalendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalendar.Click Dim text as string Dim fCalendar As New PopupCalendar() 'a form with a calendar on it fCalendar.Size = fCalendar.Calendar.Size fCalendar.Location = mLoc text = Trim(Me.txtDate.Text) If text <> vbNullString Then If (IsDate(Me.txtDate.Text)) Then fCalendar.Calendar.SelectionStart = CDate(Me.txtDate.Text) fCalendar.Calendar.SelectionEnd = CDate(Me.txtDate.Text) Else fCalendar.Calendar.SelectionStart = Today() fCalendar.Calendar.SelectionEnd = Today() End If Else fCalendar.Calendar.SelectionStart = Today() fCalendar.Calendar.SelectionEnd = Today() End If fCalendar.ShowDialog(Me) 'fCalendar will hide when date is selected or esc is pressed ... 'strange: screen will flicker whenever fCalendar hides. If Not fCalendar.Cancelled Then 'cancelled/SelectedData are custom properties of the form class Me.txtDate.Text = fCalendar.SelectedDate End If fCalendar = Nothing End Sub Quote .nerd
*Gurus* divil Posted March 13, 2003 *Gurus* Posted March 13, 2003 You can get the absolute position of the mouse cursor (which is what the location of your form should be set to) using Cursor.Position. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.