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


C# DataObject.SetText方法代码示例

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


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

示例1: SETextBox_MouseDown

        private void SETextBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (MouseButtons == MouseButtons.Left && !string.IsNullOrEmpty(_dragText))
            {
                Point pt = new Point(e.X, e.Y);
                int index = GetCharIndexFromPosition(pt);
                if (index >= _dragStartFrom && index <= _dragStartFrom + _dragText.Length)
                {
                    // re-make selection
                    SelectionStart = _dragStartFrom;
                    SelectionLength = _dragText.Length;

                    DataObject dataObject = new DataObject();
                    dataObject.SetText(_dragText, TextDataFormat.UnicodeText);
                    dataObject.SetText(_dragText, TextDataFormat.Text);

                    _dragFromThis = true;
                    if (Control.ModifierKeys == Keys.Control)
                    {
                        _dragRemoveOld = false;
                        DoDragDrop(dataObject, DragDropEffects.Copy);
                    }
                    else if (Control.ModifierKeys == Keys.None)
                    {
                        _dragRemoveOld = true;
                        DoDragDrop(dataObject, DragDropEffects.Move);
                    }
                }
            }
        }
开发者ID:radinamatic,项目名称:subtitleedit,代码行数:30,代码来源:SETextBox.cs

示例2: copyAllMenuCommand_Click

 void copyAllMenuCommand_Click(object sender, EventArgs e)
 {
     if (logBox.TextLength > 0)
     {
         DataObject o = new DataObject();
         o.SetText(logBox.Text.Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine), TextDataFormat.Text);
         o.SetText(logBox.Rtf, TextDataFormat.Rtf);
         Helper.CopyObjectToClipboardSafe(o);
     }
 }
开发者ID:greeduomacro,项目名称:phoenix,代码行数:10,代码来源:LogPage.cs

示例3: lbl_drag_MouseDown

        private void lbl_drag_MouseDown(object sender, MouseEventArgs e)
        {
            DataObject data = new DataObject();
            var dave = new Person() { Name = "Dave", Age = 4 };
            var cf_htmlDave = ClipboardUtil.textToCF_HTML(JObject.FromObject(dave).ToString());

            data.SetText(cf_htmlDave, TextDataFormat.Html);
            data.SetText("We can also attach Text.", TextDataFormat.Text);
            lbl_drag.DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Move);
        }
开发者ID:openfin,项目名称:dragdrop-dotnet-openfin-demo,代码行数:10,代码来源:Form1.cs

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

示例5: CopyAsCodeBlock

        public void CopyAsCodeBlock()
        {
            //{\rtf\ansi{\fonttbl{\f0 Cousine;}}{\colortbl;\red0\green0\blue255;}\f0 \fs18        \cf1 void\cf0  test()\par         \{\par             \cf1 int\cf0  i = 0; \par         \}\par }

            // Change selection starting point by removing white space
            int leftWhiteSpaceCount = _selection.Text.Length - _selection.Text.TrimStart(' ').Length;
            _selection.MoveToLineAndOffset(_selection.TopPoint.Line, _selection.TopPoint.DisplayColumn + leftWhiteSpaceCount, true);

            //SendKeys.SendWait("^(c)");  // copy selected
            _selection.Copy();

            DataObject dataObject = (DataObject)Clipboard.GetDataObject();
            DataObject newDataObject = new DataObject();

            // clear text
            string text = dataObject.GetText();

            int len = text.Length;
            text = text.TrimStart(null);
            int firstLineStartIndex = text.Length - text.TrimStart(null).Length;
            int secondLineStartIndex = firstLineStartIndex + 8;

            var sb = new StringBuilder();

            string[] lines = text.Split(new[] { "\r\n" }, StringSplitOptions.None);
            sb.AppendLine(lines[0].TrimStart(' '));
            for (var i = 1; i < lines.Length; i++)
            {
                sb.AppendLine(lines[i].Substring(secondLineStartIndex));
            }

            newDataObject.SetText(sb.ToString());
            sb.Clear();

            // rich text
            string rtf = (string)dataObject.GetData(DataFormats.Rtf);

            // change font
            rtf = rtf.Replace(@"{\fonttbl{\f0 Cousine;}}", @"{\fonttbl{\f0 Consolas;}}");

            string[] rtfLines = rtf.Split(new[] { @"\par " }, StringSplitOptions.None);

            sb.AppendLine(rtfLines[0]);
            for (var i = 1; i < rtfLines.Length; i++)
            {
                sb.Append(@"\par ");
                if (rtfLines[i].Length > secondLineStartIndex)
                {
                    sb.Append(rtfLines[i].Substring(secondLineStartIndex));
                }
                else
                {
                    sb.Append(rtfLines[i]);
                }
            }
            newDataObject.SetData(DataFormats.Rtf, sb.ToString());

            Clipboard.SetDataObject(newDataObject);
        }
开发者ID:ssekoguchi,项目名称:vsaddin11,代码行数:59,代码来源:TextSelectionManager.cs

示例6: lbl_drag_plain_MouseDown

 private void lbl_drag_plain_MouseDown(object sender, MouseEventArgs e)
 {
     DataObject data = new DataObject();
     var ana= new Person() {Name = "Ana", Age = 56 };
     var json_stringAna = JObject.FromObject(ana).ToString();
     data.SetText(json_stringAna, TextDataFormat.Text);
     lbl_drag_plain.DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Move);
 }
开发者ID:openfin,项目名称:dragdrop-dotnet-openfin-demo,代码行数:8,代码来源:Form1.cs

示例7: Application_ThreadException

 static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     if (MessageBox.Show(string.Format("An error has occurred.  Copy details to the clipboard?\n\n{0}", e.Exception), "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         DataObject obj = new DataObject();
         obj.SetText(e.Exception.ToString());
         Clipboard.SetDataObject(obj, true);
     }
 }
开发者ID:markmanching,项目名称:virtual-artisan-s3mods,代码行数:9,代码来源:Program.cs

示例8: GetDataObject

 public static DataObject GetDataObject(IEnumerable<string> paths, bool includeAsText = true)
 {
     var dataObject = new DataObject();
       var pathCollection = new StringCollection();
       pathCollection.AddRange(paths.ToArray());
       dataObject.SetFileDropList(pathCollection);
       if (includeAsText)
     dataObject.SetText(string.Join(Environment.NewLine, paths));
       return dataObject;
 }
开发者ID:jeffton,项目名称:PFSearch2,代码行数:10,代码来源:ShellTools.cs

示例9: ClipboardButton_Click

        private void ClipboardButton_Click(object sender, EventArgs e)
        {
            var data = new DataObject();
            RTFTranslator rtf_translator = new RTFTranslator();

            ActiveDefinition.setTranslator(rtf_translator);
            rtf_translator.Export();
            data.SetText(rtf_translator.getValue(), TextDataFormat.Rtf);
            Clipboard.SetDataObject(data);
        }
开发者ID:rrajaguk,项目名称:arrayParser,代码行数:10,代码来源:MainPage.cs

示例10: MakeDataObject

		public DataObject MakeDataObject() {
			var data = new DataObject();
			data.SetData(typeof(WordListEntries), this);

			var sb = new StringBuilder();
			foreach (var item in Items) {
				CsvUtilities.AppendCSVValue(sb, item.Phrase);
				sb.Append(',');
				CsvUtilities.AppendCSVValue(sb, item.Translation);
				sb.AppendLine();
			}
			data.SetText(sb.ToString(), TextDataFormat.CommaSeparatedValue);

			sb.Length = 0;
			foreach (var item in Items)
				sb.Append(item.Phrase).Append(" -- ").AppendLine(item.Translation);
			data.SetText(sb.ToString());

			// TODO: More formats
			return data;
		}
开发者ID:dbremner,项目名称:szotar,代码行数:21,代码来源:WordListEntries.cs

示例11: Main

 static void Main()
 {
     try
     {
         Dictionary<UInt64, string> keynames = new Dictionary<ulong, string>();
         try
         {
             STBLVault.InitializeKeyNameMap(Path.Combine(Application.StartupPath, "STBL.txt"));
         }
         catch (Exception e)
         {
             MessageBox.Show(string.Format("Error opening stbl.txt: {0}", e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         try
         {
             STBLVault.InitializeKeyNameMap(STBLVault.UserMapFilename);
         }
         catch (Exception e)
         {
             e.ToString();
         }
         Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new Form1());
     }
     catch (Exception ex)
     {
         if (MessageBox.Show(string.Format("An error has occurred.  Copy details to the clipboard?\n\n{0}", ex), "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             DataObject obj = new DataObject();
             obj.SetText(ex.ToString());
             Clipboard.SetDataObject(obj, true);
         }
     }
 }
开发者ID:markmanching,项目名称:virtual-artisan-s3mods,代码行数:36,代码来源:Program.cs

示例12: OnItemDrag

		private void OnItemDrag(object sender, ItemDragEventArgs e)
		{
			// Only allow dragging of one item at a time, so deselect all other items
			foreach (ListViewItem lvi in _listView.Items)
			{
				if (lvi != e.Item)
					lvi.Selected = false;
			}

			ListViewItem draggedItem = (ListViewItem) e.Item;

			DataObject data = new DataObject();
			if (DragOutside)
			{
			    data.SetData(draggedItem.Tag);
			    data.SetText(draggedItem.Tag.ToString(),TextDataFormat.UnicodeText);
			}
			if (DragReorder)
				data.SetData(draggedItem);

			_listView.DoDragDrop(data, DragDropEffects.Move);
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:22,代码来源:GalleryView.cs

示例13: OnKeyDown

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Tab || e.KeyCode == Keys.Oemcomma || e.KeyCode == Keys.Return || e.KeyCode == Keys.Space)
            {
                this.SetFocusEditorIndex((this.focusEditor + 1) % this.editor.Length, true);
                e.Handled = true;
            }
            else if ((e.KeyCode == Keys.C || e.KeyCode == Keys.X) && e.Control)
            {
                if (this.focusEditor == -1)
                {
                    string valString = this.editor.Select(ve => ve.Value).ToString(", ");
                    DataObject data = new DataObject();
                    data.SetText(valString);
                    data.SetData(this.DisplayedValue);
                    Clipboard.SetDataObject(data);
                    this.SetFocusEditorIndex(-1, true);
                    if (e.KeyCode == Keys.X)
                    {
                        for (int i = 0; i < this.editor.Length; i++)
                            this.editor[i].Value = 0;
                    }
                    e.Handled = true;
                }
                else
                {
                    this.editor[this.focusEditor].OnKeyDown(e);
                }
            }
            else if (e.KeyCode == Keys.V && e.Control)
            {
                if (this.focusEditor == -1)
                {
                    DataObject data = Clipboard.GetDataObject() as DataObject;
                    bool success = false;
                    if (data.GetDataPresent(this.DisplayedValue.GetType()))
                    {
                        this.SetValue(data.GetData(this.DisplayedValue.GetType()));
                        this.PerformGetValue();
                        this.OnEditingFinished(FinishReason.LeapValue);
                        this.SetFocusEditorIndex(-1, true);
                        success = true;
                    }
                    else if (data.ContainsText())
                    {
                        string valString = data.GetText();
                        string[] token = valString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < Math.Min(token.Length, this.editor.Length); i++)
                        {
                            token[i] = token[i].Trim();
                            decimal val;
                            if (decimal.TryParse(token[i], out val))
                            {
                                this.editor[i].Value = val;
                                success = true;
                            }
                        }
                        if (success)
                        {
                            this.PerformSetValue();
                            this.PerformGetValue();
                            this.OnEditingFinished(FinishReason.LeapValue);
                            this.SetFocusEditorIndex(-1, true);
                        }
                    }

                    if (!success) System.Media.SystemSounds.Beep.Play();
                    e.Handled = true;
                }
                else
                {
                    this.editor[this.focusEditor].OnKeyDown(e);
                }
            }
            else
            {
                if (this.focusEditor != -1)
                    this.editor[this.focusEditor].OnKeyDown(e);
                else
                {
                    for (int i = 0; i < this.editor.Length; i++)
                    {
                        this.editor[i].OnKeyDown(e);
                        if (e.Handled)
                        {
                            this.SetFocusEditorIndex(i, false);
                            break;
                        }
                    }
                }
            }
            base.OnKeyDown(e);
        }
开发者ID:hbcameleon,项目名称:duality,代码行数:93,代码来源:VectorPropertyEditor.cs

示例14: CreateProtectedDataObject

        private static DataObject CreateProtectedDataObject(string strText)
        {
            DataObject d = new DataObject();
            AttachIgnoreFormat(d);

            Debug.Assert(strText != null); if(strText == null) return d;

            if(strText.Length > 0) d.SetText(strText);
            return d;
        }
开发者ID:saadware,项目名称:kpn,代码行数:10,代码来源:ClipboardUtil.cs

示例15: OnKeyDown

        public void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.ControlKey)
                this.EmitInvalidate();

            if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Right)
            {
                this.ShowDropDown();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Down && e.Control)
            {
                this.ShowDropDown();
                //int index = this.dropdownItems.IndexOf(this.selectedObject);
                //this.selectedObject = this.dropdownItems[(index + 1) % this.dropdownItems.Count];
                //this.EmitEdited();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Up && e.Control)
            {
                this.ShowDropDown();
                //int index = this.dropdownItems.IndexOf(this.selectedObject);
                //this.selectedObject = this.dropdownItems[(index + this.dropdownItems.Count - 1) % this.dropdownItems.Count];
                //this.EmitEdited();
                e.Handled = true;
            }
            else if (e.Control && e.KeyCode == Keys.C)
            {
                if (this.selectedObject != null)
                {
                    DataObject data = new DataObject();
                    data.SetText(this.selectedObjStr);
                    data.SetData(ClipboardDataFormat, this.selectedObject);
                    Clipboard.SetDataObject(data);
                }
                else
                    Clipboard.Clear();
                e.Handled = true;
            }
            else if (e.Control && e.KeyCode == Keys.V)
            {
                bool success = false;
                if (Clipboard.ContainsData(ClipboardDataFormat) || Clipboard.ContainsText())
                {
                    object pasteObjProxy = null;
                    if (Clipboard.ContainsData(ClipboardDataFormat))
                    {
                        object pasteObj = Clipboard.GetData(ClipboardDataFormat);
                        pasteObjProxy = this.dropdownItems.FirstOrDefault(obj => object.Equals(obj, pasteObj));
                    }
                    else if (Clipboard.ContainsText())
                    {
                        string pasteObj = Clipboard.GetText();
                        pasteObjProxy = this.dropdownItems.FirstOrDefault(obj => obj != null && obj.ToString() == pasteObj);
                    }
                    if (pasteObjProxy != null)
                    {
                        if (this.selectedObject != pasteObjProxy)
                        {
                            this.selectedObject = pasteObjProxy;
                            this.selectedObjStr = this.DefaultValueStringGenerator(this.selectedObject);
                            this.EmitInvalidate();
                            this.EmitEdited(this.selectedObject);
                        }
                        success = true;
                    }
                }
                if (!success) System.Media.SystemSounds.Beep.Play();
                e.Handled = true;
            }
        }
开发者ID:highordersoft,项目名称:winforms,代码行数:71,代码来源:ComboBoxEditorTemplate.cs


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