tags:

views:

2088

answers:

7
A: 

Simply set the z-layer value for it (CSS), like so:

style="z-layer:1;"

TravisO
I think he's talking about Winfoms
Tigraine
yes, it is winforms. My original post was incorrect, sorry! I need more sleep.. it is midnight here....
deadcat
+1  A: 

This is a CSS problem.

You should set the z-index on the div containing the popup calendar. Have a look at the tutorial on w3schools:

http://www.w3schools.com/Css/pr_pos_z-index.asp

EDIT: Now that you've realised you're actually using WinForms, please ignore my answer :)

Winston Smith
+3  A: 

The screenshots looks like a Windows Forms applications, so my answer is for winforms.

I guess the best solution would be to create a customcontrol that itself uses the datetime picker that already has the behavior.

Show a empty textbox until it gets clicked, then display the datetimepicker.

That would save you a bunch of code..

Tigraine
That's a good suggestion, I will give that a try tomorrow. I'm still keen to know if there is a way to answer my original question though! :)
deadcat
This custom control should do the trick: http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c9645
deadcat
It turned out I couldn't go down this path. I started with the control above, but there is no way to set the control up so that the user can tab to it and start typing - an important feature for the user I am writing for.
deadcat
+1  A: 

I'm not 100% sure, but a quick look at the DateTimePicker class on Reflector takes me to the SafeNativeMethods.SetWindowPos internal class.

You can override the SetBoundsCore from the base Control class or, like Tigraine stated, create a custom control based on the DateTimePicker.

Hope it helps, Bruno Figueiredo

Bruno Shine
+1  A: 

I ran into this when trying to implement a custom control and discovered that it's a remarkably hard problem. There's no built-in functionality within the Windows.Forms model to support controls whose display area extends outside the client area of their container.

You basically have to either use the Windows API or draw your controls inside a Form with AlwaysOnTop set. Both approaches are harder than they should be. I ended up redesigning my control so that instead of displaying its expanded contents in a dropdown it used a modal dialog. This was a pretty unsatisfying solution, but I spent a couple of weeks trying other approaches and could never get anything that worked consistently across all use cases (like disappearing when the application loses focus).

Robert Rossney
A: 

The reason that your control gets chopped off is because it is a child control of the form that you reside on. Any control on the form must be contained by the form, hence it gets chopped off.

I haven't done this in .Net, but had a similar problem in VB6. The solution then was to set the parent of the popup window (the calendar in your case) to be the desktop. This will allow it to extend beyond the boundaries of your form. You'll have to do some P/Invoke magic to find the hWnd of the popup, and another P/Invoke to set the parent.

Dan R
+7  A: 

The ToolStripDropDown control has this functionallity so by inheriting from it we can make a simple PopupWindow.

/// <summary>
/// A simple popup window that can host any System.Windows.Forms.Control
/// </summary>
public class PopupWindow : System.Windows.Forms.ToolStripDropDown
{
    private System.Windows.Forms.Control _content;
    private System.Windows.Forms.ToolStripControlHost _host;

    public PopupWindow(System.Windows.Forms.Control content)
    {
        //Basic setup...
        this.AutoSize = false;
        this.DoubleBuffered = true;
        this.ResizeRedraw = true;

        this._content = content;
        this._host = new System.Windows.Forms.ToolStripControlHost(content);

        //Positioning and Sizing
        this.MinimumSize = content.MinimumSize;
        this.MaximumSize = content.Size;
        this.Size = content.Size;
        content.Location = Point.Empty;

        //Add the host to the list
        this.Items.Add(this._host);
    }
}

Usage:

PopupWindow popup = new PopupWindow(MyControlToHost);
popup.Show(new Point(100,100));
...
popup.Close();
Jesper Palm
Holy crap, this code is the most awesome code ever.I'm integrating this into my user control, thanks.
deadcat
I got it working.Is there anyway to remove the border?
deadcat
I've implemented this code, but the popup keeps stealing focus. Is there a way to prevent this?
jblaske