在处理用户控件剪贴板复制 [英] Handle clipboard copy on UserControl

查看:142
本文介绍了在处理用户控件剪贴板复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有复杂的UserControl(网格,编辑控件的网格等),我想要处理CTRL + C键盘快捷方式,但我不想通过编辑控件(文本框,组合框等)禁用本机功能。 ..)。如果CTRL + C不是由其他内部控制处理,我想自己处理它(从网格等复制整行)。

I have complex UserControl (grid, edit controls for grid, etc...) and I want handle CTRL+C keyboard shortcut, however I don't want disable a native functions by edit controls (textboxes, comboboxes, etc...). If the CTRL+C is not handled by other inner controls I want handle it by myself (copy whole row(s) from grid, etc...).

I尝试在UserControl中覆盖WndProc方法,并检查WM_COPY和WM_COPYDATA,但它不工作。它只适用于最终目标控件(例如TextBox)。

I tried override WndProc method in UserControl and check for WM_COPY and WM_COPYDATA, but it doesn't work. It works only on final target control (TextBox for example).

推荐答案

可以通过覆盖ProcessCmdKey检查文本框是否具有焦点。例如:

You can do this by overriding ProcessCmdKey(). Check if a text box has the focus. For example:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        if (keyData == (Keys.Control | Keys.C)) {
            var box = this.ActiveControl as TextBoxBase;
            if (box == null) {
                // Do your stuff
                MessageBox.Show("Copy!");
                return true;
            }
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

这篇关于在处理用户控件剪贴板复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆