本文整理汇总了C#中System.Windows.DataObject.SetText方法的典型用法代码示例。如果您正苦于以下问题:C# DataObject.SetText方法的具体用法?C# DataObject.SetText怎么用?C# DataObject.SetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DataObject
的用法示例。
在下文中一共展示了DataObject.SetText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnCopy_Click
private void btnCopy_Click(object sender, RoutedEventArgs e)
{
var data = new DataObject();
data.SetText(RTF, TextDataFormat.Rtf);
data.SetText(rtf.Text, TextDataFormat.Text);
Clipboard.SetDataObject(data);
}
示例2: ToClipboard
public static void ToClipboard(this List<FrameworkElement> elements)
{
var builderTabbedText = new StringBuilder();
var builderCsvText = new StringBuilder();
foreach (var element in elements)
{
string tabbedText = element.DataContext.ToString();
string csvText = element.DataContext.ToString();
builderTabbedText.AppendLine(tabbedText);
builderCsvText.AppendLine(csvText);
}
// data object to hold our different formats representing the element
var dataObject = new DataObject();
dataObject.SetText(builderTabbedText.ToString());
// Convert the CSV text to a UTF-8 byte stream before adding it to the container object.
var bytes = Encoding.UTF8.GetBytes(builderCsvText.ToString());
var stream = new System.IO.MemoryStream(bytes);
dataObject.SetData(DataFormats.CommaSeparatedValue, stream);
// lets start with the text representation
// to make is easy we will just assume the object set as the DataContext has the ToString method overrideen and we use that as the text
dataObject.SetData(DataFormats.CommaSeparatedValue, stream);
// now place our object in the clipboard
Clipboard.SetDataObject(dataObject, true);
}
示例3: SetClipboardData
/// <summary>
/// Sets the clipboard data for the specified table.
/// </summary>
/// <param name="table">The table.</param>
/// <remarks>
/// This method sets the TEXT (tab delimited) and CSV data. Like in Excel the CSV delimiter is either comma or semicolon, depending on the current culture.
/// </remarks>
public static void SetClipboardData(this IList<IList<string>> table)
{
if (table == null)
{
Clipboard.Clear();
return;
}
var textString = table.ToTextString();
var csvString = table.ToCsvString();
var dataObject = new DataObject();
dataObject.SetText(textString);
dataObject.SetText(csvString, TextDataFormat.CommaSeparatedValue);
Clipboard.SetDataObject(dataObject);
}
示例4: SetClipboardData
/// <summary>
/// Places the provided data on the clipboard overriding what is currently in the clipboard.
/// </summary>
/// <param name="isSingleLine">Indicates whether a single line was automatically cut/copied by
/// the editor. If <c>true</c> the clipboard contents are tagged with a special moniker.</param>
public static void SetClipboardData(string html, string rtf, string unicode, bool isSingleLine, bool isBoxCopy)
{
DataObject data = new DataObject();
if (unicode != null)
{
data.SetText(unicode, TextDataFormat.UnicodeText);
data.SetText(unicode, TextDataFormat.Text);
}
if (html != null)
{
data.SetText(GetHtmlForClipboard(html), TextDataFormat.Html);
}
if (rtf != null)
{
data.SetText(rtf, TextDataFormat.Rtf);
}
if (isSingleLine)
{
data.SetData(ClipboardLineBasedCutCopyTag, new object());
}
if (isBoxCopy)
{
data.SetData(BoxSelectionCutCopyTag, new object());
}
try
{
// Use delay rendering to set the data in the clipboard to prevent 2 clipboard change
// notifications to clipboard change listeners.
Clipboard.SetDataObject(data, false);
}
catch (System.Runtime.InteropServices.ExternalException)
{
}
}
示例5: NumberTextBox
static NumberTextBox()
{
EventManager.RegisterClassHandler(
typeof(NumberTextBox),
DataObject.PastingEvent,
(DataObjectPastingEventHandler)((sender, e) =>
{
if (!IsDataValid(e.DataObject))
{
DataObject data = new DataObject();
data.SetText(String.Empty);
e.DataObject = data;
e.Handled = false;
}
}));
}
示例6: ToDataObject
public static DataObject ToDataObject(this TransferDataSource data)
{
var retval = new DataObject ();
foreach (var type in data.DataTypes) {
var value = data.GetValue (type);
if (type == TransferDataType.Text)
retval.SetText ((string)value);
else if (type == TransferDataType.Uri) {
var uris = new StringCollection ();
uris.Add (((Uri)value).LocalPath);
retval.SetFileDropList (uris);
} else
retval.SetData (type.Id, TransferDataSource.SerializeValue (value));
}
return retval;
}
示例7: SetHtml
/// <summary>
/// Sets the TextDataFormat.Html on the data object to the specified html fragment.
/// This helper methods takes care of creating the necessary CF_HTML header.
/// </summary>
public static void SetHtml(DataObject dataObject, string htmlFragment)
{
if (dataObject == null)
throw new ArgumentNullException("dataObject");
if (htmlFragment == null)
throw new ArgumentNullException("htmlFragment");
string htmlStart = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" + Environment.NewLine
+ "<HTML>" + Environment.NewLine
+ "<BODY>" + Environment.NewLine
+ "<!--StartFragment-->" + Environment.NewLine;
string htmlEnd = "<!--EndFragment-->" + Environment.NewLine + "</BODY>" + Environment.NewLine + "</HTML>" + Environment.NewLine;
string dummyHeader = BuildHeader(0, 0, 0, 0);
// the offsets are stored as UTF-8 bytes (see CF_HTML documentation)
int startHTML = dummyHeader.Length;
int startFragment = startHTML + htmlStart.Length;
int endFragment = startFragment + Encoding.UTF8.GetByteCount(htmlFragment);
int endHTML = endFragment + htmlEnd.Length;
string cf_html = BuildHeader(startHTML, endHTML, startFragment, endFragment) + htmlStart + htmlFragment + htmlEnd;
Debug.WriteLine(cf_html);
dataObject.SetText(cf_html, TextDataFormat.Html);
}
示例8: Copy
/// <summary>
/// Copies the selected cells.
/// </summary>
/// <param name="separator">The separator.</param>
public void Copy(string separator)
{
var text = this.SelectionToString(separator);
var array = this.SelectionToArray();
var dataObject = new DataObject();
dataObject.SetText(text);
if (AreAllElementsSerializable(array))
{
try
{
dataObject.SetData(typeof(DataGrid), array);
}
catch (Exception e)
{
// nonserializable values?
Debug.WriteLine(e);
}
}
Clipboard.SetDataObject(dataObject);
}
示例9: DataObject
bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y)
{
var dataObject = new DataObject();
dataObject.SetText(dragData.FragmentText, TextDataFormat.Text);
dataObject.SetText(dragData.FragmentText, TextDataFormat.UnicodeText);
dataObject.SetText(dragData.FragmentHtml, TextDataFormat.Html);
// TODO: The following code block *should* handle images, but GetFileContents is
// not yet implemented.
//if (dragData.IsFile)
//{
// var bmi = new BitmapImage();
// bmi.BeginInit();
// bmi.StreamSource = dragData.GetFileContents();
// bmi.EndInit();
// dataObject.SetImage(bmi);
//}
UiThreadRunAsync(delegate
{
var results = DragDrop.DoDragDrop(this, dataObject, GetDragEffects(mask));
managedCefBrowserAdapter.OnDragSourceEndedAt(0, 0, GetDragOperationsMask(results));
managedCefBrowserAdapter.OnDragSourceSystemDragEnded();
});
return true;
}
示例10: CopyWholeLine
static bool CopyWholeLine(TextArea textArea, DocumentLine line)
{
ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
string text = textArea.Document.GetText(wholeLine);
// Ensure we use the appropriate newline sequence for the OS
text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
DataObject data = new DataObject();
if (ConfirmDataFormat(textArea, data, DataFormats.UnicodeText))
data.SetText(text);
// Also copy text in HTML format to clipboard - good for pasting text into Word
// or to the SharpDevelop forums.
if (ConfirmDataFormat(textArea, data, DataFormats.Html)) {
IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));
}
if (ConfirmDataFormat(textArea, data, LineSelectedType)) {
MemoryStream lineSelected = new MemoryStream(1);
lineSelected.WriteByte(1);
data.SetData(LineSelectedType, lineSelected, false);
}
var copyingEventArgs = new DataObjectCopyingEventArgs(data, false);
textArea.RaiseEvent(copyingEventArgs);
if (copyingEventArgs.CommandCancelled)
return false;
try {
Clipboard.SetDataObject(data, true);
} catch (ExternalException) {
// Apparently this exception sometimes happens randomly.
// The MS controls just ignore it, so we'll do the same.
return false;
}
textArea.OnTextCopied(new TextEventArgs(text));
return true;
}
示例11: CutOrDelete
private void CutOrDelete(IEnumerable<SnapshotSpan> projectionSpans, bool isCut)
{
Debug.Assert(CurrentLanguageBuffer != null);
StringBuilder deletedText = null;
// split into multiple deletes that only affect the language/input buffer:
ITextBuffer affectedBuffer = (ReadingStandardInput) ? StandardInputBuffer : CurrentLanguageBuffer;
using (var edit = affectedBuffer.CreateEdit())
{
foreach (var projectionSpan in projectionSpans)
{
var spans = TextView.BufferGraph.MapDownToBuffer(projectionSpan, SpanTrackingMode.EdgeInclusive, affectedBuffer);
foreach (var span in spans)
{
if (isCut)
{
if (deletedText == null)
{
deletedText = new StringBuilder();
}
deletedText.Append(span.GetText());
}
edit.Delete(span);
}
}
edit.Apply();
}
// copy the deleted text to the clipboard:
if (deletedText != null)
{
var data = new DataObject();
if (TextView.Selection.Mode == TextSelectionMode.Box)
{
data.SetData(BoxSelectionCutCopyTag, new object());
}
data.SetText(deletedText.ToString());
_window.InteractiveWindowClipboard.SetDataObject(data, true);
}
}
示例12: CopyImpl
public override void CopyImpl()
{
if (rtf != null)
{
var dataObject = new DataObject();
dataObject.SetData(DataFormats.Rtf, rtf);
dataObject.SetText(text);
Clipboard.SetDataObject(dataObject);
}
else
{
System.Windows.Clipboard.SetText(text);
}
}
示例13: CopyToClipboard
bool CopyToClipboard(string text, string htmlText, bool isFullLineData, bool isBoxData) {
try {
var dataObj = new DataObject();
dataObj.SetText(text);
if (isFullLineData)
dataObj.SetData(VS_COPY_FULL_LINE_DATA_FORMAT, true);
if (isBoxData)
dataObj.SetData(VS_COPY_BOX_DATA_FORMAT, true);
if (htmlText != null)
dataObj.SetData(DataFormats.Html, htmlText);
Clipboard.SetDataObject(dataObj);
return true;
}
catch (ExternalException) {
return false;
}
}
示例14: SetClipboard
private static void SetClipboard(string dataType, string data)
{
DataObject copyBuffer = new DataObject();
copyBuffer.SetData(dataType, "Y");
copyBuffer.SetText(data);
try
{
Clipboard.SetDataObject(copyBuffer);
}
catch (System.Runtime.InteropServices.COMException)
{
System.Threading.Thread.Sleep(0);
try
{
Clipboard.SetDataObject(copyBuffer);
}
catch (System.Runtime.InteropServices.COMException e)
{
ConfigManager.LogManager.LogError("Error writing to clipboard.", e);
}
}
}
示例15: Copy
public override CopyDataObject Copy(bool removeSelection)
{
CopyDataObject temp = base.Copy(removeSelection);
DataObject data = new DataObject();
data.SetImage(temp.Image);
XElement rootElement = new XElement(this.GetType().Name);
rootElement.Add(new XElement("SessionId", sessionString));
rootElement.Add(textManager.Serialize());
rootElement.Add(new XElement("payload", temp.XElement));
MathEditorData med = new MathEditorData { XmlString = rootElement.ToString() };
data.SetData(med);
//data.SetText(GetSelectedText());
if (temp.Text != null)
{
data.SetText(temp.Text);
}
Clipboard.SetDataObject(data, true);
if (removeSelection)
{
DeSelect();
AdjustCarets();
}
return temp;
}