Force DataTimePicker to open calendar by F12

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrus

    Force DataTimePicker to open calendar by F12

    I need that WinForms DateTimePicker opens calendar when F12 key is pressed.
    I tried code below but got error

    Property or indexer 'System.Windows .Forms.KeyEvent Args.KeyCode' cannot be
    assigned to -- it is read only

    How to fix ?

    Andrus.

    public class NullableDateTim ePicker : DateTimePicker {

    protected override void OnKeyDown(KeyEv entArgs e) {
    base.OnKeyDown( e);
    if (e.KeyCode == Keys.F12)
    e.KeyCode = Keys.F4;
    }
    }

  • Cowboy \(Gregory A. Beamer\)

    #2
    Re: Force DataTimePicker to open calendar by F12

    I am not understanding why you would need to set the KeyCode to something
    else, if all you want to do is open the DateTimePicker.

    If you absolutely need to pass down to base, you can create an EventArg

    KeyPressEventAr gs ea = new KeyPressEventAr gs(KeyChar.F4)
    base.OnKeyPress (ea);

    But, I would think you can pop the control without intercepting the
    keystroke.

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    Subscribe to my blog


    or just read it:


    *************** *************** **************
    | Think outside the box! |
    *************** *************** **************
    "Andrus" <kobruleht2@hot .eewrote in message
    news:uRp9swj0IH A.4912@TK2MSFTN GP03.phx.gbl...
    >I need that WinForms DateTimePicker opens calendar when F12 key is pressed.
    I tried code below but got error
    >
    Property or indexer 'System.Windows .Forms.KeyEvent Args.KeyCode' cannot be
    assigned to -- it is read only
    >
    How to fix ?
    >
    Andrus.
    >
    public class NullableDateTim ePicker : DateTimePicker {
    >
    protected override void OnKeyDown(KeyEv entArgs e) {
    base.OnKeyDown( e);
    if (e.KeyCode == Keys.F12)
    e.KeyCode = Keys.F4;
    }
    }

    Comment

    • Andrus

      #3
      Re: Force DataTimePicker to open calendar by F12

      Gregory,
      >I am not understanding why you would need to set the KeyCode to something
      >else, if all you want to do is open the DateTimePicker.
      They is no method or property which can be used to open calendar so I tried
      this as last effort.
      If you absolutely need to pass down to base, you can create an EventArg
      >
      KeyPressEventAr gs ea = new KeyPressEventAr gs(KeyChar.F4)
      base.OnKeyPress (ea);

      I tried

      protected override void OnKeyPress(KeyP ressEventArgs e)
      {
      if (e.KeyChar == (char)Keys.F12)
      {
      KeyPressEventAr gs ea = new KeyPressEventAr gs((char)Keys.F 4);
      base.OnKeyPress (ea);
      return;
      }

      and

      protected override void OnKeyDown(KeyEv entArgs e)
      {
      if (e.KeyCode == Keys.F12)
      {
      KeyPressEventAr gs ea = new KeyPressEventAr gs((char)Keys.F 4);
      base.OnKeyPress (ea);
      return;
      }

      but F12 still does not open calendar.
      But, I would think you can pop the control without intercepting the
      keystroke.
      Which method or property I should use for this ?

      Andrus.
      "Andrus" <kobruleht2@hot .eewrote in message
      news:uRp9swj0IH A.4912@TK2MSFTN GP03.phx.gbl...
      >>I need that WinForms DateTimePicker opens calendar when F12 key is
      >>pressed.
      >I tried code below but got error
      >>
      >Property or indexer 'System.Windows .Forms.KeyEvent Args.KeyCode' cannot be
      >assigned to -- it is read only
      >>
      >How to fix ?
      >>
      >Andrus.
      >>
      >public class NullableDateTim ePicker : DateTimePicker {
      >>
      >protected override void OnKeyDown(KeyEv entArgs e) {
      > base.OnKeyDown( e);
      > if (e.KeyCode == Keys.F12)
      > e.KeyCode = Keys.F4;
      > }
      >}
      >

      Comment

      • Stephany Young

        #4
        Re: Force DataTimePicker to open calendar by F12

        Try using SendKeys to send it an F4.

        Look up SendKeys in the help.


        "Andrus" <kobruleht2@hot .eewrote in message
        news:%23TNM1l30 IHA.616@TK2MSFT NGP03.phx.gbl.. .
        Gregory,
        >
        >>I am not understanding why you would need to set the KeyCode to something
        >>else, if all you want to do is open the DateTimePicker.
        >
        They is no method or property which can be used to open calendar so I
        tried
        this as last effort.
        >
        >If you absolutely need to pass down to base, you can create an EventArg
        >>
        >KeyPressEventA rgs ea = new KeyPressEventAr gs(KeyChar.F4)
        >base.OnKeyPres s(ea);
        >
        >
        I tried
        >
        protected override void OnKeyPress(KeyP ressEventArgs e)
        {
        if (e.KeyChar == (char)Keys.F12)
        {
        KeyPressEventAr gs ea = new
        KeyPressEventAr gs((char)Keys.F 4);
        base.OnKeyPress (ea);
        return;
        }
        >
        and
        >
        protected override void OnKeyDown(KeyEv entArgs e)
        {
        if (e.KeyCode == Keys.F12)
        {
        KeyPressEventAr gs ea = new
        KeyPressEventAr gs((char)Keys.F 4);
        base.OnKeyPress (ea);
        return;
        }
        >
        but F12 still does not open calendar.
        >
        >But, I would think you can pop the control without intercepting the
        >keystroke.
        >
        Which method or property I should use for this ?
        >
        Andrus.
        >
        >"Andrus" <kobruleht2@hot .eewrote in message
        >news:uRp9swj0I HA.4912@TK2MSFT NGP03.phx.gbl.. .
        >>>I need that WinForms DateTimePicker opens calendar when F12 key is
        >>>pressed.
        >>I tried code below but got error
        >>>
        >>Property or indexer 'System.Windows .Forms.KeyEvent Args.KeyCode' cannot
        >>be
        >>assigned to -- it is read only
        >>>
        >>How to fix ?
        >>>
        >>Andrus.
        >>>
        >>public class NullableDateTim ePicker : DateTimePicker {
        >>>
        >>protected override void OnKeyDown(KeyEv entArgs e) {
        >> base.OnKeyDown( e);
        >> if (e.KeyCode == Keys.F12)
        >> e.KeyCode = Keys.F4;
        >> }
        >>}
        >>
        >

        Comment

        Working...