Windows Develop Bookmark and Share   
 index > Windows Forms Designer > User Control
 

User Control

I have a user controlthat pops a calendar when a button is selected. This control is the child of several other controls, and I want the calendar to surface to the top of the form and stay alligned with the button that called it. Currently I have tried BringToFront() and also make the parent of the calendar the top most form. None of these have worked as expected.

private void calendarDisplay(int height, int width, bool display)

{

this.Height = height;

this.Width = width;

monthCalendar.Parent = this;

monthCalendar.BringToFront();

monthCalendar.SetBounds(4, 26 , width, height);

if (display)

{

monthCalendar.Show();

}

else

{

monthCalendar.Visible = display;

}

}

Any suggestions?

Thanks

JMaloney  Tuesday, November 20, 2007 6:05 PM

It's better to use a ToolStripDropDownHost to host theMonthCalendar,and add the ToolStripDropDownHost to a ToolStripDropDown control. The following sample demonstrates how to do this.

Code Block

:

public

thisnewEventHandler

privatebool

privateTextBox

privateButton

privateMonthCalendar

ToolStripDropDown

voidobjectEventArgs

thistrue

thisnewMonthCalendar

thisnewDateRangeEventHandler

popup = ();

Padding

Padding

ToolStripControlHostnewToolStripControlHostthis

Padding

Padding

thisthis

this

thisnewTextBox

this

this

thisthis

this

thisDateTime

thisthis

thisnewButton

thisthis

this

this

this

thisnewPaintEventHandler

thisnewEventHandler

thisthis

(Continued)


Code Block


calendar_DateSelected( sender, e)

this

thistrue

this

voidobjectPaintEventArgs

ControlPaint

this

ButtonState

privatevoidobjectEventArgs

if

Point

thisthis

this

this

thisthis

else

this

It's better to use a ToolStripDropDownHost to host theMonthCalendar,and add the ToolStripDropDownHost to a ToolStripDropDown control. The following sample demonstrates how to do this.

Code Block

:

public

thisnewEventHandler

privatebool

privateTextBox

privateButton

privateMonthCalendar

ToolStripDropDown

voidobjectEventArgs

thistrue

thisnewMonthCalendar

thisnewDateRangeEventHandler

popup = ();

Padding

Padding

ToolStripControlHostnewToolStripControlHostthis

Padding

Padding

thisthis

this

thisnewTextBox

this

this

thisthis

this

thisDateTime

thisthis

thisnewButton

thisthis

this

this

this

thisnewPaintEventHandler

thisnewEventHandler

thisthis

(Continued)


Code Block


calendar_DateSelected( sender, e)

this

thistrue

this

voidobjectPaintEventArgs

ControlPaint

this

ButtonState

privatevoidobjectEventArgs

if

Point

thisthis

this

this

thisthis

else

this

Hi Zhi-Xin Ye - MSFT,

Many Thanks for that reply. I have gone through it butI was just wondering is the program still using calendar in the same form. I have to customize the user control and drag and drop it to other pages.

I am also unsure about the toolstrip drop down and how to use that control..

Sreeram2  Monday, April 28, 2008 9:41 AM

You can use google to search for other answers

Custom Search

More Threads

• adding data to comboBox
• Need to access primary key of a bound datagrid
• Bug - Getting the SelectedItem in ListBox
• Sharing My Controls
• How to let application override event handler in User Control?
• move cursor right in datagridview
• Resize DesignSurface
• how to enable smarttag on Custom designerhost implementation
• Sort Icon in Grid View(Win Forms)
• Pass parameters from designer to autogenerated controls