C1PrintPreviewDialog.KeyDown Event

Posted by: ivan.stanojkovski on 13 December 2020, 12:02 am EST

    • Post Options:
    • Link

    Posted 13 December 2020, 12:02 am EST

    Hello

    We have dynamically create C1PrintPreviewDialog, and we want to handle the KeyDown event to Close the dialog when ESC key is pressed.

    This is the sample of our code, but the event doesn’t trigger.

            Dim PrintPreviewDialog As New C1.Win.C1Preview.C1PrintPreviewDialog
            AddHandler PrintPreviewDialog.KeyDown, AddressOf Form_KeyDown
            PrintPreviewDialog.ShowDialog()
    
        Public Shared Sub Form_KeyDown(sender As Object, e As KeyEventArgs)
            Try
                Select Case e.KeyCode
                    Case Keys.Escape
                        TryCast(sender, Form).Close()
                End Select
            Catch
            End Try
        End Sub
    
    

    Can you help us.

    Best regards.

  • Posted 13 December 2020, 6:53 pm EST

    Hi,

    You need to set the KeyPreview property to true, which enables the form to receive the key events before the focused control. Please refer to the sample attached.

    If you have any other questions, please let me know.

    Regards,

    Prabhat Sharma.

    C1PrintPreviewDialog.zip

  • Posted 13 December 2020, 7:07 pm EST

    Thank you so much.

    Best Regards.

  • Posted 20 December 2020, 10:09 pm EST

    Hi, again.

    I face the same problem when I use C1RibbonPreview.

    Again, events like KeyDown and KeyPress don’t trigger.

    But as I see the property KeyPreview does not exist in C1RibbonPreview.

    Any suggestions ?

    This is my example:

    
        Private Sub C1RibbonPreview1_KeyDown(sender As Object, e As KeyEventArgs) Handles C1RibbonPreview.KeyDown
            Select Case e.KeyCode
                Case Keys.Escape : Me.Close()
            End Select
        End Sub
    
    

    Best regards.

  • Posted 21 December 2020, 9:48 pm EST

    Hi,

    You will need to override the ProcessCmdKey function to fire the KeyDown event for any key since RibbonPreview is a UserControl. You can use the following code to achieve this :

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keydata As Keys) As Boolean
    
     
    
            If keydata = Keys.Escape Then
    
                OnKeyDown(New KeyEventArgs(keydata))
    
            End If
    
            ProcessCmdKey = MyBase.ProcessCmdKey(msg, keydata)
    
    End Function
    

    This will fire the KeyDown event for RibbonPreview when the Escape key is used. Please refer to the sample attached.

    Regards,

    Prabhat Sharma.

    RibbonPreviewKeyDowm.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels