当前位置: 首页>>代码示例>>C#>>正文


C# DataObject.SetData方法代码示例

本文整理汇总了C#中System.Windows.Forms.DataObject.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# DataObject.SetData方法的具体用法?C# DataObject.SetData怎么用?C# DataObject.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.DataObject的用法示例。


在下文中一共展示了DataObject.SetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Copy

        /// <summary>
        /// Copy selected text into Clipboard
        /// </summary>
        public static void Copy(FastColoredTextBox textbox)
        {
            if (textbox.Selection.IsEmpty)
            {
                textbox.Selection.Expand();
            }

            if (!textbox.Selection.IsEmpty)
            {
                var exp = new ExportToHTML();
                exp.UseBr = false;
                exp.UseNbsp = false;
                exp.UseStyleTag = true;
                string html = "<pre>" + exp.GetHtml(textbox.Selection.Clone()) + "</pre>";
                var data = new DataObject();
                data.SetData(DataFormats.UnicodeText, true, textbox.Selection.Text);
                data.SetData(DataFormats.Html, PrepareHtmlForClipboard(html));
                data.SetData(DataFormats.Rtf, new ExportToRTF().GetRtf(textbox.Selection.Clone()));
                //
                var thread = new Thread(() => SetClipboard(data));
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();
            }
        }
开发者ID:rickaas,项目名称:FastColoredTextBox,代码行数:28,代码来源:EditorCommands.cs

示例2: RtfTextTest

		public void RtfTextTest ()
		{
			string rtf_text = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}{\*\generator Mono RichTextBox;}\pard\f0\fs16 hola\par}";
			string plain_text = "hola";

			Clipboard.SetText (rtf_text, TextDataFormat.Rtf);

			Assert.AreEqual (false, Clipboard.ContainsText (TextDataFormat.Text), "#A1");
			Assert.AreEqual (false, Clipboard.ContainsText (TextDataFormat.UnicodeText), "#A2");
			Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.Rtf), "#A3");
			Assert.AreEqual (rtf_text, Clipboard.GetText (TextDataFormat.Rtf), "#A4");

			// Now use a IDataObject, so we can have more than one format at the time
			DataObject data = new DataObject ();
			data.SetData (DataFormats.Rtf, rtf_text);
			data.SetData (DataFormats.UnicodeText, plain_text);

			Clipboard.SetDataObject (data);

			Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.Text), "#B1");
			Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.UnicodeText), "#B2");
			Assert.AreEqual (true, Clipboard.ContainsText (TextDataFormat.Rtf), "#B3");
			Assert.AreEqual (rtf_text, Clipboard.GetText (TextDataFormat.Rtf), "#B4");
			Assert.AreEqual (plain_text, Clipboard.GetText (), "#B5");

			Clipboard.Clear ();
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:27,代码来源:ClipboardTest.cs

示例3: treeView1_ItemDrag

        private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            // gx2. jsx, jsc reflector
            // ?

            // http://support.microsoft.com/kb/307968

            // we can drag it into scite
            // DragDrop.DoDragDrop returns only after the complete drag-drop process is finished,
            // http://w3facility.org/question/dodragdrop-freezes-winforms-app-sometimes/
            // https://msdn.microsoft.com/en-us/library/ms649011(VS.85).aspx

            // http://www.codeproject.com/Articles/17266/Drag-and-Drop-Items-in-a-WPF-ListView

            Console.WriteLine("treeView1_ItemDrag"); ;

            // http://stackoverflow.com/questions/1772102/c-sharp-drag-and-drop-from-my-custom-app-to-notepad
            var x = new DataObject(
                "treeView1_ItemDrag " + new { e.Item }
            );


            // like props/ reg keys/ version nodes
            x.SetData("text/nodes/0", "hello");
            x.SetData("text/nodes/1", "world");

            // https://msdn.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop(v=vs.110).aspx
            //this.DoDragDrop("treeView1_ItemDrag " + new { e.Item }, DragDropEffects.Copy);
            treeView1.DoDragDrop(x, DragDropEffects.Copy);

            // https://code.google.com/p/chromium/issues/detail?id=31037
            // https://searchcode.com/codesearch/view/32985148/
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:33,代码来源:ApplicationControl.cs

示例4: CopyTextToClipboard

		bool CopyTextToClipboard(string stringToCopy, bool asLine)
		{
			if (stringToCopy.Length > 0) {
				DataObject dataObject = new DataObject();
				dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy);
				if (asLine) {
					MemoryStream lineSelected = new MemoryStream(1);
					lineSelected.WriteByte(1);
					dataObject.SetData(LineSelectedType, false, lineSelected);
				}
				// Default has no highlighting, therefore we don't need RTF output
				if (textArea.Document.HighlightingStrategy.Name != "Default") {
					dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
				}
				OnCopyText(new CopyTextEventArgs(stringToCopy));
				
				// Work around ExternalException bug. (SD2-426)
				// Best reproducable inside Virtual PC.
				try {
					Clipboard.SetDataObject(dataObject, true, 10, 50);
				} catch (ExternalException) {
					Application.DoEvents();
					try {
						Clipboard.SetDataObject(dataObject, true, 10, 50);
					} catch (ExternalException) {}
				}
				return true;
			} else {
				return false;
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:31,代码来源:TextAreaClipboardHandler.cs

示例5: Copy

 public void Copy()
 {
     IDataObject clips = new DataObject();
     clips.SetData(DataFormats.Bitmap, this.opened_image.get_bitmap());
     clips.SetData(DataFormats.Text, this.opened_image.get_file_name());
     Clipboard.SetDataObject(clips, true);
 }
开发者ID:AlexanderHosnie,项目名称:IP-FCIS,代码行数:7,代码来源:PictureForm.cs

示例6: copyToClipboard

        public static void copyToClipboard(List<Frame> frames)
        {
            if (frames.Count == 0)
            {
                return;
            }

            DataObject data = new DataObject();
            data.SetData(frames.ToArray());

            if (frames.Count == 1)
            {
                // Not necessary, but Microsoft recommends that we should
                // place data on the clipboard in as many formats possible.
                data.SetData(frames[0]);
            }

            StringBuilder sb = new StringBuilder();
            foreach (Frame frame in frames)
            {
                sb.AppendLine(frame.getTabSeparatedString());
            }
            data.SetText(sb.ToString());

            Clipboard.SetDataObject(data, true);
        }
开发者ID:Moomers,项目名称:penguins,代码行数:26,代码来源:Frame.cs

示例7: ToDataObject

 public DataObject ToDataObject()
 {
     DataObject obj = new DataObject();
     obj.SetData(DataFormats.Serializable, this);
     obj.SetData(DataFormats.Text, Texte);
     return obj;
 }
开发者ID:bilale,项目名称:Test,代码行数:7,代码来源:RendezVous.cs

示例8: CopyTextToClipboard

		bool CopyTextToClipboard(string stringToCopy)
		{
			if (stringToCopy.Length > 0) {
				DataObject dataObject = new DataObject();
				dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy);
				// Default has no highlighting, therefore we don't need RTF output
				if (textArea.Document.HighlightingStrategy.Name != "Default") {
					dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
				}
				OnCopyText(new CopyTextEventArgs(stringToCopy));
				
				// Work around ExternalException bug. (SD2-426)
				// Best reproducable inside Virtual PC.
				// SetDataObject has "retry" parameters, but apparently a call to "DoEvents"
				// is necessary for the workaround to work.
				int i = 0;
				while (true) {
					try {
						Clipboard.SetDataObject(dataObject, true, 5, 50);
						return true;
					} catch (ExternalException) {
						if (i++ > 5)
							throw;
					}
					System.Threading.Thread.Sleep(50);
					Application.DoEvents();
					System.Threading.Thread.Sleep(50);
				}
			} else {
				return false;
			}
		}
开发者ID:viticm,项目名称:pap2,代码行数:32,代码来源:TextAreaClipboardHandler.cs

示例9: GetDataObjectFromText

 protected override IDataObject GetDataObjectFromText(string text)
 {
     DataObject obj2 = new DataObject();
     obj2.SetData(DataFormats.Text, text);
     obj2.SetData(DataFormats.Html, text);
     return obj2;
 }
开发者ID:ikvm,项目名称:webmatrix,代码行数:7,代码来源:HtmlDocumentLanguage.cs

示例10: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     DataObject data = new DataObject();
     data.SetData(DataFormats.Text, textBox1.Text);
     string html = "<p>" + textBox1.Text + "</p>";
     data.SetData(DataFormats.Html, html);
     Clipboard.SetDataObject(data, true);
 }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:8,代码来源:Form1.cs

示例11: CopyUrl

		public static void CopyUrl(string url, string name = null)
		{
			var dto = new DataObject(DataFormats.Html, string.Format(_htmlTemplate, url));
			dto.SetData(DataFormats.Text, url);
			if (!string.IsNullOrEmpty(name))
				dto.SetData(MessageSubjectFormat, name);
			Clipboard.SetDataObject(dto);
		}
开发者ID:rsdn,项目名称:janus,代码行数:8,代码来源:ClipboardHelper.cs

示例12: GetDataObject

 /// <summary>
 /// Get data object with given html and plaintext ready to be used for clipboard or drag & drop.
 /// </summary>
 /// <param name="html">a html fragment</param>
 /// <param name="plainText">the plain text</param>
 public static DataObject GetDataObject(string html, string plainText)
 {
     var data = GetHtmlData(html);
     var dataObject = new DataObject();
     dataObject.SetData(DataFormats.Html, data);
     dataObject.SetData(DataFormats.Text, plainText);
     return dataObject;
 }
开发者ID:Alister742,项目名称:ParseKit,代码行数:13,代码来源:HtmlClipboardUtils.cs

示例13: copyButton_Click

        private void copyButton_Click(object sender, EventArgs e)
        {
            DataObject m_data = new DataObject();

            m_data.SetData(DataFormats.Rtf, true, outputBox.Rtf);
            m_data.SetData(DataFormats.Text, true, outputBox.Text);
            Clipboard.SetDataObject(m_data, true);
            MessageBox.Show("Copied to Clipboard!");
        }
开发者ID:ammunoz,项目名称:CitationTool,代码行数:9,代码来源:mlaWindow.cs

示例14: SetClipboardTextContent

 /// <summary>
 /// Writes given text to the clipboard.
 /// </summary>
 public static void SetClipboardTextContent(bool formatted, object[] data)
 {
     IDataObject dataObject = new DataObject();
     dataObject.SetData(DataFormats.UnicodeText, data[0]);
     if (formatted)
     {
         dataObject.SetData(DataFormats.Rtf, data[1]);
         dataObject.SetData(DataFormats.Html, data[2]);
     }
     Clipboard.SetDataObject(dataObject);
 }
开发者ID:MrksKwsnck,项目名称:Wlipper,代码行数:14,代码来源:Clipboarding.cs

示例15: new_data_object

        private static DataObject new_data_object(string html, string plain) {
            html = html ?? String.Empty;
            var fragment = html_data_string(html);

            if (Environment.Version.Major < 4 && html.Length != Encoding.UTF8.GetByteCount(html))
                fragment = Encoding.Default.GetString(Encoding.UTF8.GetBytes(fragment));

            var dataObject = new DataObject();
            dataObject.SetData(DataFormats.Html, fragment);
            dataObject.SetData(DataFormats.Text, plain);
            dataObject.SetData(DataFormats.UnicodeText, plain);
            return dataObject;
        }
开发者ID:printedheart,项目名称:logwizard,代码行数:13,代码来源:clipboard_util.cs


注:本文中的System.Windows.Forms.DataObject.SetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。