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


C# Forms.DataObject类代码示例

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


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

示例1: CopyButtonClick

        private void CopyButtonClick(object sender, EventArgs e)
        {
            var dateTime = DateTime.Parse(DateTextBox.Text, DateTextBox.Culture, DateTimeStyles.AssumeLocal);

            var timeSpan = dateTime.ToUniversalTime() - Epoch;

            var dataObject = new DataObject();

            var messagePlain = string.Format(
                "[{0:hh:mm:ss}] {1}: {2}",
                dateTime,
                AuthorFullNameTextBox.Text,
                MessageTextBox.Text);
            var messageXml = string.Format(
                "<quote author=\"{0}\" timestamp=\"{1}\">{2}</quote>",
                AuthorTextBox.Text,
                timeSpan.TotalSeconds,
                MessageTextBox.Text);

            dataObject.SetData("System.String", messagePlain);
            dataObject.SetData("UnicodeText", messagePlain);
            dataObject.SetData("Text", messagePlain);
            dataObject.SetData("SkypeMessageFragment", new MemoryStream(Encoding.UTF8.GetBytes(messageXml)));
            dataObject.SetData("Locale", new MemoryStream(BitConverter.GetBytes(CultureInfo.CurrentCulture.LCID)));
            dataObject.SetData("OEMText", messagePlain);

            Clipboard.SetDataObject(dataObject, true);
        }
开发者ID:jefrimustapa,项目名称:skype-quote-generator,代码行数:28,代码来源:MainForm.cs

示例2: CloneClipboard

        private IDataObject CloneClipboard(IDataObject obj)
        {
            if (obj == null)
                return null;

            string[] formats = obj.GetFormats();
            if (formats.Length == 0)
                return null;

            IDataObject newObj = new DataObject();
            
            foreach (string format in formats)
            {
				if (format.Contains("EnhancedMetafile")) //Ignore this. Cannot be processed in .NET
					continue;

				object o = obj.GetData(format);

                if (o != null)
                {
                    newObj.SetData(o);
                }
            }

            return newObj;
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:26,代码来源:ClipboardSnapshot.cs

示例3: label2_MouseDown

        private void label2_MouseDown(object sender, MouseEventArgs e)
        {
            // Start drag-and-drop if left mouse goes down over this label
              if (e.Button == MouseButtons.Left)
              {
            // Crete a new data object
            DataObject data = new DataObject();

            // Get the TextBox text
            string dragString = this.textBox1.Text;

            // If the TextBox text was empty then use a default string
            if (string.IsNullOrEmpty(dragString))
              dragString = "Empty string";

            // Set the DataOject's data to a new SampleCsDragData object which
            // can be serialized. If you use an object that does not support the
            // serialize interface then you will NOT be able to drag and drop the
            // item onto a different session of Rhino.
            data.SetData(new SampleCsDragData(dragString));

            // Start drag-and-drop
            this.DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Move);
              }
        }
开发者ID:mcneel,项目名称:Rhino4Samples_DotNet,代码行数:25,代码来源:SampleCsDragDropForm.cs

示例4: 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

示例5: 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

示例6: OnDropOnLayerListCtrl

        /// <summary>
        /// This method is called when the drag and drop operation is completed and
        /// the item being dragged was dropped on the Rhino layer list control.
        /// </summary>
        public override bool OnDropOnLayerListCtrl(IWin32Window layerListCtrl, int layerIndex, DataObject data, DragDropEffects dropEffect, Point point)
        {
            SampleCsDragData dragData = GetSampleCsDragData(data);
              if (null == dragData)
            return false;

              if (layerIndex < 0)
              {
            MessageBox.Show(
              RhUtil.RhinoApp().MainWnd(),
              "String \"" + dragData.DragString + "\" Dropped on layer list control, not on a layer",
              "SampleCsDragDrop",
              MessageBoxButtons.OK,
              MessageBoxIcon.Information
              );
              }
              else
              {
            MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();
            if (null != doc && layerIndex < doc.m_layer_table.LayerCount())
            {
              MessageBox.Show(
            RhUtil.RhinoApp().MainWnd(),
            "String \"" + dragData.DragString + "\" Dropped on layer \"" + doc.m_layer_table[layerIndex].m_name + "\"",
            "SampleCsDragDrop",
            MessageBoxButtons.OK,
            MessageBoxIcon.Information
            );
            }
              }

              return true;
        }
开发者ID:mcneel,项目名称:Rhino4Samples_DotNet,代码行数:37,代码来源:SampleCsDropTarget.cs

示例7: 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

示例8: DeserializeFromData

 protected override void DeserializeFromData(DataObject data)
 {
     ConvertOperation convert = new ConvertOperation(data, ConvertOperation.Operation.Convert);
     if (convert.CanPerform(this.editedCmpType))
     {
         var refQuery = convert.Perform(this.editedCmpType);
         if (refQuery != null)
         {
             Component[] refArray = refQuery.Cast<Component>().ToArray();
             this.component = (refArray != null && refArray.Length > 0) ? refArray[0] : null;
             this.PerformSetValue();
             this.PerformGetValue();
             this.OnEditingFinished(FinishReason.LeapValue);
         }
     }
     else if (convert.CanPerform(typeof(GameObject)))
     {
         GameObject obj = convert.Perform<GameObject>().FirstOrDefault();
         Component cmp = obj != null ? obj.GetComponent(this.editedCmpType) : null;
         if (cmp != null)
         {
             this.component = cmp;
             this.PerformSetValue();
             this.PerformGetValue();
             this.OnEditingFinished(FinishReason.LeapValue);
         }
     }
 }
开发者ID:Naturaldoc,项目名称:duality,代码行数:28,代码来源:ComponentRefPropertyEditor.cs

示例9: 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

示例10: 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

示例11: 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

示例12: OnActivateTool

        /// <summary>
        /// Called when the tool is activated.
        /// </summary>
        protected override void OnActivateTool()
        {
            if(Selection.SelectedItems.Count == 0)
                return;

            try
            {
                //Clear the Anchors otherwise subsequent Copy operations will raise an exception due to the fact that the Anchors class is a static helper class
                Anchors.Clear();
                //this will create a volatile collection of entities, they need to be unwrapped!
                //I never managed to get things working by putting the serialized collection directly onto the Clipboad. Thanks to Leppie's suggestion it works by
                //putting the Stream onto the Clipboard, which is weird but it works.
                MemoryStream copy = Selection.SelectedItems.ToStream();
                DataFormats.Format format = DataFormats.GetFormat(typeof(CopyTool).FullName);
                IDataObject dataObject = new DataObject();
                dataObject.SetData(format.Name, false, copy);
                Clipboard.SetDataObject(dataObject, false);
            }
            catch (Exception exc)
            {
                throw new InconsistencyException("The Copy operation failed.", exc);
            }
            finally
            {
                DeactivateTool();
            }
        }
开发者ID:JackWangCUMT,项目名称:mathnet-yttrium,代码行数:30,代码来源:CopyTool.cs

示例13: 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

示例14: Send

        public void Send(string archiveFilename, CancellationToken cancellationToken, SimpleProgressCallback progressCallback = null)
        {
            // create drop effect memory stream
            byte[] moveEffect = new byte[] { (byte) (performCut ? 2 : 5), 0, 0, 0 };
            MemoryStream dropEffect = new MemoryStream();
            dropEffect.Write(moveEffect, 0, moveEffect.Length);

            // create file data object
            DataObject data = new DataObject();
            data.SetFileDropList(new StringCollection { archiveFilename });
            data.SetData("Preferred DropEffect", dropEffect);

            // create STA thread that'll work with Clipboard object
            Thread copyStaThread = new Thread(() =>
                {
                    Clipboard.Clear();
                    Clipboard.SetDataObject(data, true);
                })
                {
                    Name = "Clipboard copy thread"
                };

            copyStaThread.SetApartmentState(ApartmentState.STA);

            // start the thread and wait for it to finish
            copyStaThread.Start();
            copyStaThread.Join();
        }
开发者ID:korj,项目名称:Shtirlitz,代码行数:28,代码来源:ClipboardCopier.cs

示例15: copyToolStripMenuItem_Click

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*
            SceneJS scene = (SceneJS)treeView1.Nodes[0].Tag;
            if (scene != null)
            {
                object obj = scene.GetSelectedObject();
                if( obj != null )
                {
                    Clipboard.SetData("WebGLSceneObject", obj);
                }
            }
            */

            Clipboard.Clear();
            List<object> selected = new List<object>();
            foreach (TreeNode n in treeView1.SelectedNodes)
            {
                selected.Add(n.Tag);
            }

            DataFormats.Format df = DataFormats.GetFormat(typeof(List<object>).FullName);
            IDataObject dato = new DataObject();
            dato.SetData(df.Name, false, selected);

            Clipboard.SetDataObject(dato, false);
        }
开发者ID:RonOHara-GG,项目名称:WebGLRenderer,代码行数:27,代码来源:Form1.cs


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