Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ShowDialog form with MonthCalendar over the button that shows calendar

Posted on 2008-11-03
6
Medium Priority
?
634 Views
Last Modified: 2011-10-19
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(104, "txtDueDate", txtDueDate.Text, Me.Panel1.Location + Me.cmdDueDateCalendar.Location)

The positioning, however is always high and too far to left.  Where am I going wrong???
0
Comment
Question by:TSFLLC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22875633
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.
0
 

Author Comment

by:TSFLLC
ID: 22876801
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("txtCheckDate", FormatCurrentDate(), Me.PointToScreen(Me.Label1.Location + Me.cmdCheckDateCalendar.Location))
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.SelectionStart = xDate
        MonthCalendar1.SelectionEnd = 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.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22876861
Can you attach a .png screen shot of what you mean by "hide"?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:TSFLLC
ID: 22877380
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
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 22879910
Try something like this example.

You may not have set the form's StartPosition to Manual.

Dim form As New TestForm() 
 
form.StartPosition = FormStartPosition.Manual 
form.Location = New Point(Me.Left + Me.ShowFormButton.Right, Me.Top + Me.ShowFormButton.Bottom) 
 
form.Show() 

Open in new window

0
 

Author Comment

by:TSFLLC
ID: 22880242
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_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInvoiceDateCalendar.Click
    If txtInvoiceDate.Text = "  /  /" Then
        Dim frm As New Misc_CalendarDateSelect(104, "txtInvoiceDate", FormatCurrentDate(), Me.PointToScreen(Me.gbInvoiceAssessment1.Location + Me.cmdInvoiceDateCalendar.Location))
        frm.ShowDialog()
    Else
        Dim frm As New Misc_CalendarDateSelect(104, "txtInvoiceDate", txtInvoiceDate.Text, Me.PointToScreen(Me.gbInvoiceAssessment1.Location + 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.SelectionStart = xDate
        MonthCalendar1.SelectionEnd = xDate
        Me.StartPosition = FormStartPosition.Manual
        Me.Location = xPoint
    End Sub


Thanks!
Phil
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question