1、 从系统剪切板获取数据
GetDataFromClipboard(){
try{
WinForms.IDataObject data = WinForms.Clipboard.GetDataObject();
if(data.GetDataPresent(WinForms.DataFormats.UnicodeText))
{
string Text = (string)data.GetData(WinForms.DataFormats.UnicodeText);
return Text ;
}
}catch{
}
return null;
}
2、剪切数据
WinForms.Clipboard.SetDataObject(strValue[i],true);//将值放入剪切板中
WinForms.Clipboard.Clear(); /// 清除剪切板中的数据
Clipboard.SetText(repo.TextFileName.TextValue);
repo.TextFileName.TextValue=Clipboard.GetText();
3、 比对剪贴板内容
/// <summary>
/// 比对剪贴板内容
/// </summary>
public static void Clipboard(string compareText,string customLogMessage){
const string NullString="(null)";
System.Windows.Forms.Clipboard.SetText("比对剪贴文本");
if(System.Windows.Forms.Clipboard.ContainsText()){
string clipboardtext = System.Windows.Forms.Clipboard.GetText();
if (customLogMessage.Trim().Equals(string.Empty)||
customLogMessage.Trim().Equals(NullString))
{
customLogMessage = "应该比对成功";
}
Ranorex.Validate.AreEqual(clipboardtext, compareText, customLogMessage);
}else{
throw new Ranorex.RanorexException("剪贴板不存在比对文本");
}
}