samedi 16 mars 2019

if else statement with keypress, clipboard notificion and WndProc c#

I make a question answer program based on a list. Now I want 2 ways to copy in my program namely when you select and the 2nd way is via clipboard.GetText (); Now I want to be able to switch via a keypress event between the ways of copying that I have made in my program. And that Notificon indicates how it will copy. I already have a small example, but unfortunately I cannot get further so far.

This is my code:

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
        {
            const int WM_DRAWCLIPBOARD = 0x308;
            if (m.Msg == WM_DRAWCLIPBOARD)
            {
                // copy when selecting   
                {
                    switch (MouseButtons)
                    {
                        case MouseButtons.Middle:
                            GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
                            break;
                    };
                }
                //copy on ctrl-c or right click copy\
                GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
            }
        }
    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        //if you type q on your keyboard you get the windows notification "Copy on select enabled."
        if (e.Control && e.KeyCode.ToString() == "q") ;
        {
            notifyIcon1.Icon = SystemIcons.Exclamation;
            notifyIcon1.BalloonTipText = "Copy on select enabled";
            notifyIcon1.ShowBalloonTip(1000);
            GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
            {
            }
        } 
    }
}

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire