views:

472

answers:

2

I'm trying to use the System.Windows.Forms.MonthCalendar control within a VSTO Excel workbook. I want the MonthCalendar to pop up when I click a button in the ribbon, but so far I can't get the control to display at all.

Private Sub DeliveryDateFromCalendarButton_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles DeliveryDateFromCalendarButton.Click
 Dim selectedFiscalYear As String = Me.FiscalYearDropDown.SelectedItem.Label
 Dim cal As System.Windows.Forms.MonthCalendar = New System.Windows.Forms.MonthCalendar()

 cal.Location = New System.Drawing.Point(Cursor.Position.X, Cursor.Position.Y)
 cal.Show()
End Sub

The calendar should pop up at the place they clicked, but alas, it fails.

+1  A: 

I ended up creating a new System.Windows.Form and adding my calendar to its Controls collection.

Not ideal, so I'm still looking for a solution, but it at least gets me a pop-up calendar.

Peder Rice
+1  A: 

I'm pretty sure you need a form in order to host a winforms control. If your goal was to have "just" the calender control appear by itself then what would the parent window be?

If you want the "appearance" of just a calender control that is easy enough, just tweak the UI properties of the form so that it has no visible border, is modal, etc, if you rewrite in WPF then your form doesn't even have to look like a form (i.e. square etc)

Anonymous Type