2010-12-04 108 views
0

如何将用户文本在其他应用程序中选择复制到应用程序中的某个变量? 使用全局热键 - 用户单击热键,然后我的应用程序将在活动窗口中捕获选定的文本。从窗口复制文本

+2

为什么不直接使用剪贴板? – Doggett 2010-12-04 10:53:50

回答

1

使用ClipBoard.GetText()方法

这的getText方法是具备predefind textdataformat的一个参数

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);