You must Sign In to post a response.
  • Category: Windows

    Showing datetime picker calendar when clicked on empty area

    Hi Team,

    I am using win forms DateTimePicker control. Currently I am getting calendar popup when clicked on arrow symbol. But I need to have calendar popup opened up when clicked on empty area (textbox) beside arrow symbol also.

    Kindly let me know how to achieve this.


    Regards,
    Venkata Rajesh M
  • #768419
    Hi ,

    We can do this in many ways.






    <script type="text/javascript">

    $(function() {

    $("#txtDate").datepicker();

    });

    </script>

    <style type="text/css">

    .ui-datepicker { font-size:8pt !important}




    The above code will perform when you add the basic Jquery in the script.
    If you use JqueryUI, this can be done very simple way. Just adding the latest JqueryUI link then add the following code.


    <script>

    $( function() {

    $( "#datepicker" ).datepicker();

    } );

    </script>

    </head>

    <body>
    <p>Date: <input type="text" id="datepicker"></p>
    //Other Elements
    </body>




    Thanks,
    Mani

  • #768421
    Hi Manigandan,

    Thanks for the reply. But my requirement is in Windows forms application with C#.

  • #768422
    Hi,

    On that case, We can check the how much length and width that we assigned for our textbox and based on that clicking that places we can pop up the calendar dialog.
    Something like this,



    public static void ShowCalendar(this DateTimePicker picker, MouseEventArgs clickEvent)
    {
    var suppressor = new EventSuppressor(picker);
    suppressor.Suppress();

    // Based on Button from the Textbox we can identify the position of our text box. Picker is button position
    int x = picker.Width - 10;
    int y = picker.Height / 2;
    int lParam = x + y * 0x00010000;

    //Now this lParam is the area where our entire text box positions
    }
    }




    So when ever the lParam is get clicked we can called the MouseDown event and call the Calendar Dialog function.


    private void dateTimePicker1_MouseDown(object sender, MouseEventArgs e)
    {
    dateTimePicker1.ShowCalendar(e);
    }

    Thanks,
    Mani


Sign In to post your comments