none
How to make datetimepicker expanded by default in c# RRS feed

  • Question

  • By default, DateTimePicker is not expanded.

    To expand, user should click the dropdown button from the control.

    I want to make calendar expanded by default.

    How to do this?

    Saturday, August 3, 2019 8:27 PM

All replies

  • A way :

    SwitchToThisWindow(DTP.Handle, true);
    SendKeys.Send("{F4}");

    with :

            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern bool SwitchToThisWindow(IntPtr hWnd, Boolean fAltTab);

    Saturday, August 3, 2019 8:55 PM
  • Hello,

    Here is a solution taken from this post.

    using System.Windows.Forms;
    
    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                Shown += Form1_Shown;
            }
    
            private void Form1_Shown(object sender, System.EventArgs e)
            {
                dateTimePicker1.Select();
                SendKeys.Send("%{DOWN}");
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, August 4, 2019 2:55 AM
    Moderator
  • Consider MonthCalendar instead of DateTimePicker.

    Sunday, August 4, 2019 7:09 AM
  • Hi Jeff0803,

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 9, 2019 6:49 AM
    Moderator