2010-12-04 6 views
0

Comment puis-je copier sélectionné par le texte de l'utilisateur dans une autre application à une variable dans mon application? Avec l'utilisation du raccourci clavier hotke-user global, mon application capture le texte sélectionné dans la fenêtre active.Copier le texte à partir de Windows

+2

Pourquoi ne pas simplement utiliser le presse-papiers? – Doggett

+0

Je n'ai pas ce texte dans le presse-papiers - je veux juste capturer le texte sélectionné à mon application avec un raccourci clavier. – djcis

Répondre

1
méthode

et cette méthode GetText

utilisation ClipBoard.GetText() est d'avoir un paramètre de TextDataFormat predefind

public enum TextDataFormat 
{ 
    // Summary: 
    //  Specifies that the text data is in the System.Windows.DataFormats.Text data 
    //  format. 
    Text = 0, 
    // 
    // Summary: 
    //  Specifies that the text data is in the System.Windows.DataFormats.UnicodeText 
    //  data format. 
    UnicodeText = 1, 
    // 
    // Summary: 
    //  Specifies that the text data is in the System.Windows.DataFormats.Rtf data 
    //  format. 
    Rtf = 2, 
    // 
    // Summary: 
    //  Specifies that the text data is in the System.Windows.DataFormats.Html data 
    //  format. 
    Html = 3, 
    // 
    // Summary: 
    //  Specifies that the text data is in the System.Windows.DataFormats.CommaSeparatedValue 
    //  data format. 
    CommaSeparatedValue = 4, 
    // 
    // Summary: 
    //  Specifies that the text data is in the System.Windows.DataFormats.Xaml data 
    //  format. 
    Xaml = 5, 
} 

so if you know that data format is Text tha n 


string text = ClipBoard.GetText(TextDataFormats.Text); 
0

Une façon est d'utiliser le presse-papiers

Questions connexes