TSFLLC
asked on
ShowDialog form with MonthCalendar over the button that shows calendar
I have various forms that contain date maskedtextboxes and a button to the right of each textbox inside either a tabcontrol, panel or both. The button will showdialog this form that contains a MonthCalendar with only a Close option in top right.
I am attempting to pass the location of the button so that the top/left corner of Calendar form can be displayed just over the top/left corner of button. Below is the code to kick off the calendar.
Dim frm As New Misc_CalendarDateSelect(10 4, "txtDueDate", txtDueDate.Text, Me.Panel1.Location + Me.cmdDueDateCalendar.Loca tion)
The positioning, however is always high and too far to left. Where am I going wrong???
I am attempting to pass the location of the button so that the top/left corner of Calendar form can be displayed just over the top/left corner of button. Below is the code to kick off the calendar.
Dim frm As New Misc_CalendarDateSelect(10
The positioning, however is always high and too far to left. Where am I going wrong???
The form's position is based on screen coordinates, and the control's position is based on client coordinates. You need to convert the client coordinates to screen coordinates, in order to position the form correctly. The Form and Control class inherit the PointToClient and PointToScreen methods for that purpose.
ASKER
Below is the code I'm using where Label1 is a label and cmdCheckDateCalendar is the button I want to set the form in front of:
Dim frm As New Misc_CalendarDateSelect("t xtCheckDat e", FormatCurrentDate(), Me.PointToScreen(Me.Label1 .Location + Me.cmdCheckDateCalendar.Lo cation))
frm.ShowDialog()
Public Sub New(ByVal xTextBox As String, ByVal xDate As Date, ByVal xPoint As Point)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
glDateField = xTextBox
MonthCalendar1.SelectionSt art = xDate
MonthCalendar1.SelectionEn d = xDate
Me.Location = Me.PointToClient(xPoint)
End Sub
The only issue I have now is that the CalendarForm does not hide the calendar button with the top left corner of the form but it hides it with the top left corner of the Calendar itself. I can live with that but I don't understand why it's doing that.
Dim frm As New Misc_CalendarDateSelect("t
frm.ShowDialog()
Public Sub New(ByVal xTextBox As String, ByVal xDate As Date, ByVal xPoint As Point)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
glDateField = xTextBox
MonthCalendar1.SelectionSt
MonthCalendar1.SelectionEn
Me.Location = Me.PointToClient(xPoint)
End Sub
The only issue I have now is that the CalendarForm does not hide the calendar button with the top left corner of the form but it hides it with the top left corner of the Calendar itself. I can live with that but I don't understand why it's doing that.
Can you attach a .png screen shot of what you mean by "hide"?
ASKER
In the image I attached I have moved the Integra Calendar form away from the Calendar button so that you could see the button. When you click the button initially, the Integra Calendar form displays over the button and the top left edge of the calendar matches up with the top left corner of the button.
What I don't understand is why the top/left corner of the Integra Calendar form (not the top/left corner of the Calendar control) doesn't match the top/left positioning of the calendar button???
Thanks.
Phil
MonthCalendar1.jpg
What I don't understand is why the top/left corner of the Integra Calendar form (not the top/left corner of the Calendar control) doesn't match the top/left positioning of the calendar button???
Thanks.
Phil
MonthCalendar1.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The issue of not setting start position to manual was my #1 problem. The code below works like a charm.
This was the conclusion to the code that worked accordingly:
From data entry form.....
Private Sub cmdInvoiceDateCalendar_Cli ck(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInvoiceDateCalendar.Cli ck
If txtInvoiceDate.Text = " / /" Then
Dim frm As New Misc_CalendarDateSelect(10 4, "txtInvoiceDate", FormatCurrentDate(), Me.PointToScreen(Me.gbInvo iceAssessm ent1.Locat ion + Me.cmdInvoiceDateCalendar. Location))
frm.ShowDialog()
Else
Dim frm As New Misc_CalendarDateSelect(10 4, "txtInvoiceDate", txtInvoiceDate.Text, Me.PointToScreen(Me.gbInvo iceAssessm ent1.Locat ion + Me.cmdInvoiceDateCalendar. Location))
frm.ShowDialog()
End If
End Sub
From MonthCalendar form....
Public Sub New(ByVal xTextBox As String, ByVal xDate As Date, ByVal xPoint As Point)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
glDateField = xTextBox
MonthCalendar1.SelectionSt art = xDate
MonthCalendar1.SelectionEn d = xDate
Me.StartPosition = FormStartPosition.Manual
Me.Location = xPoint
End Sub
Thanks!
Phil
This was the conclusion to the code that worked accordingly:
From data entry form.....
Private Sub cmdInvoiceDateCalendar_Cli
If txtInvoiceDate.Text = " / /" Then
Dim frm As New Misc_CalendarDateSelect(10
frm.ShowDialog()
Else
Dim frm As New Misc_CalendarDateSelect(10
frm.ShowDialog()
End If
End Sub
From MonthCalendar form....
Public Sub New(ByVal xTextBox As String, ByVal xDate As Date, ByVal xPoint As Point)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
glDateField = xTextBox
MonthCalendar1.SelectionSt
MonthCalendar1.SelectionEn
Me.StartPosition = FormStartPosition.Manual
Me.Location = xPoint
End Sub
Thanks!
Phil