SetText() public méthode

public SetText ( string textData ) : void
textData string
Résultat void
        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);
                    }
                }
            }
        }
Exemple #2
0
 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);
     }
 }
        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);
        }
Exemple #4
0
        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);
        }
        public static SWF.IDataObject ToSwf(this TransferDataSource data)
        {
            var result = new SWF.DataObject();

            foreach (var type in data.DataTypes)
            {
                var value = data.GetValue(type);

                if (type == TransferDataType.Text)
                {
                    result.SetText((string)value);
                }
                else if (type == TransferDataType.Uri)
                {
                    var uris = new StringCollection();
                    uris.Add(((Uri)value).LocalPath);
                    result.SetFileDropList(uris);
                }
                else
                {
                    result.SetData(type.Id, value);
                }
            }

            return(result);
        }
        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);
        }
 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);
 }
 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);
     }
 }
Exemple #9
0
        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);
        }
Exemple #10
0
 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;
 }
Exemple #11
0
		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;
		}
 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);
         }
     }
 }
Exemple #13
0
		public static void SetClipboardData(ISurface surface) {
			DataObject dataObject = new DataObject();

			// This will work for Office and most other applications
			//ido.SetData(DataFormats.Bitmap, true, image);

			MemoryStream dibStream = null;
			MemoryStream dibV5Stream = null;
			MemoryStream pngStream = null;
			Image imageToSave = null;
			bool disposeImage = false;
			try {
				SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);
				// Create the image which is going to be saved so we don't create it multiple times
				disposeImage = ImageOutput.CreateImageFromSurface(surface, outputSettings, out imageToSave);
				try {
					// Create PNG stream
					if (config.ClipboardFormats.Contains(ClipboardFormat.PNG)) {
						pngStream = new MemoryStream();
						// PNG works for e.g. Powerpoint
						SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);
						ImageOutput.SaveToStream(imageToSave, null, pngStream, pngOutputSettings);
						pngStream.Seek(0, SeekOrigin.Begin);
						// Set the PNG stream
						dataObject.SetData(FORMAT_PNG, false, pngStream);
					}
				} catch (Exception pngEX) {
					LOG.Error("Error creating PNG for the Clipboard.", pngEX);
				}

				try {
					if (config.ClipboardFormats.Contains(ClipboardFormat.DIB)) {
						using (MemoryStream tmpBmpStream = new MemoryStream()) {
							// Save image as BMP
							SurfaceOutputSettings bmpOutputSettings = new SurfaceOutputSettings(OutputFormat.bmp, 100, false);
							ImageOutput.SaveToStream(imageToSave, null, tmpBmpStream, bmpOutputSettings);

							dibStream = new MemoryStream();
							// Copy the source, but skip the "BITMAPFILEHEADER" which has a size of 14
							dibStream.Write(tmpBmpStream.GetBuffer(), BITMAPFILEHEADER_LENGTH, (int)tmpBmpStream.Length - BITMAPFILEHEADER_LENGTH);
						}

						// Set the DIB to the clipboard DataObject
						dataObject.SetData(DataFormats.Dib, true, dibStream);
					}
				} catch (Exception dibEx) {
					LOG.Error("Error creating DIB for the Clipboard.", dibEx);
				}

				// CF_DibV5
				try {
					if (config.ClipboardFormats.Contains(ClipboardFormat.DIBV5)) {
						// Create the stream for the clipboard
						dibV5Stream = new MemoryStream();

						// Create the BITMAPINFOHEADER
						BITMAPINFOHEADER header = new BITMAPINFOHEADER(imageToSave.Width, imageToSave.Height, 32);
						// Make sure we have BI_BITFIELDS, this seems to be normal for Format17?
						header.biCompression = BI_COMPRESSION.BI_BITFIELDS;
						// Create a byte[] to write
						byte[] headerBytes = BinaryStructHelper.ToByteArray<BITMAPINFOHEADER>(header);
						// Write the BITMAPINFOHEADER to the stream
						dibV5Stream.Write(headerBytes, 0, headerBytes.Length);

						// As we have specified BI_COMPRESSION.BI_BITFIELDS, the BitfieldColorMask needs to be added
						BitfieldColorMask colorMask = new BitfieldColorMask();
						// Make sure the values are set
						colorMask.InitValues();
						// Create the byte[] from the struct
						byte[] colorMaskBytes = BinaryStructHelper.ToByteArray<BitfieldColorMask>(colorMask);
						Array.Reverse(colorMaskBytes);
						// Write to the stream
						dibV5Stream.Write(colorMaskBytes, 0, colorMaskBytes.Length);

						// Create the raw bytes for the pixels only
						byte[] bitmapBytes = BitmapToByteArray((Bitmap)imageToSave);
						// Write to the stream
						dibV5Stream.Write(bitmapBytes, 0, bitmapBytes.Length);

						// Set the DIBv5 to the clipboard DataObject
						dataObject.SetData(FORMAT_17, true, dibV5Stream);
					}
				} catch (Exception dibEx) {
					LOG.Error("Error creating DIB for the Clipboard.", dibEx);
				}
				
				// Set the HTML
				if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) {
					string tmpFile = ImageOutput.SaveToTmpFile(surface, new SurfaceOutputSettings(OutputFormat.png, 100, false), null);
					string html = getHTMLString(surface, tmpFile);
					dataObject.SetText(html, TextDataFormat.Html);
				} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {
					string html;
					using (MemoryStream tmpPNGStream = new MemoryStream()) {
						SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);
						// Do not allow to reduce the colors, some applications dislike 256 color images
						// reported with bug #3594681
						pngOutputSettings.DisableReduceColors = true;
						// Check if we can use the previously used image
						if (imageToSave.PixelFormat != PixelFormat.Format8bppIndexed) {
							ImageOutput.SaveToStream(imageToSave, surface, tmpPNGStream, pngOutputSettings);
						} else {
							ImageOutput.SaveToStream(surface, tmpPNGStream, pngOutputSettings);
						}
						html = getHTMLDataURLString(surface, tmpPNGStream);
					}
					dataObject.SetText(html, TextDataFormat.Html);
				}
			} finally {
				// we need to use the SetDataOject before the streams are closed otherwise the buffer will be gone!
				// Check if Bitmap is wanted
				if (config.ClipboardFormats.Contains(ClipboardFormat.BITMAP)) {
					dataObject.SetImage(imageToSave);
					// Place the DataObject to the clipboard
					SetDataObject(dataObject, true);
				} else {
					// Place the DataObject to the clipboard
					SetDataObject(dataObject, true);
				}
				
				if (pngStream != null) {
					pngStream.Dispose();
					pngStream = null;
				}

				if (dibStream != null) {
					dibStream.Dispose();
					dibStream = null;
				}
				if (dibV5Stream != null) {
					dibV5Stream.Dispose();
					dibV5Stream = null;
				}
				// cleanup if needed
				if (disposeImage && imageToSave != null) {
					imageToSave.Dispose();
				}
			}
		}
Exemple #14
0
		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);
		}
        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);
        }
Exemple #16
0
        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;
        }
        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;
            }
        }
		void DoCopyValue(object sender, EventArgs e) {
			var data = hexView.GetSelection();

			var dataObj = new DataObject();
			dataObj.SetData("Binary Data", true, new MemoryStream(data));

			dataObj.SetText(Encoding.ASCII.GetString(data));

			Clipboard.SetDataObject(dataObj, true);
		}
		public void TestText ()
		{
			DataObject d = new DataObject ();

			d.SetText ("yo");

			Assert.AreEqual (false, d.ContainsAudio (), "A1");
			Assert.AreEqual (false, d.ContainsFileDropList (), "A2");
			Assert.AreEqual (false, d.ContainsImage (), "A3");
			Assert.AreEqual (true, d.ContainsText (), "A4");
			Assert.AreEqual (false, d.ContainsText (TextDataFormat.CommaSeparatedValue), "A5");

			Assert.AreEqual ("yo", d.GetText (), "A6");
			Assert.AreEqual ("yo", d.GetData (DataFormats.StringFormat), "A6-1");
			
			d.SetText ("<html></html>", TextDataFormat.Html);
			Assert.AreEqual (true, d.ContainsText (), "A7");
			Assert.AreEqual (false, d.ContainsText (TextDataFormat.CommaSeparatedValue), "A8");
			Assert.AreEqual (true, d.ContainsText (TextDataFormat.Html), "A9");
			Assert.AreEqual (false, d.ContainsText (TextDataFormat.Rtf), "A10");
			Assert.AreEqual (true, d.ContainsText (TextDataFormat.Text), "A11");
			Assert.AreEqual (true, d.ContainsText (TextDataFormat.UnicodeText), "A12");

			// directly put a string
			d.SetData ("yo");

			Assert.AreEqual (true, d.ContainsText (TextDataFormat.Text), "A13");
			Assert.AreEqual (true, d.ContainsText (TextDataFormat.UnicodeText), "A14");

			Assert.AreEqual ("yo", d.GetData (DataFormats.StringFormat), "A15");
			Assert.AreEqual ("yo", d.GetData (DataFormats.Text), "A16");
			Assert.AreEqual ("yo", d.GetData (DataFormats.UnicodeText), "A17");
		}
Exemple #20
0
 private void copySelectedEntriesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (selectedEntries.Count == 0)
     return;
        StringBuilder csvText = new StringBuilder();
        StringBuilder rawText = new StringBuilder();
        LogSessionDictionary logEntries = task.Log.Entries;
        DateTime sessionTime = (DateTime)filterSessionCombobox.SelectedItem;
        csvText.AppendLine(S._("Session: {0:F}", sessionTime));
        rawText.AppendLine(S._("Session: {0:F}", sessionTime));
        int currentEntryIndex = 0;
        foreach (LogEntry entry in logEntries[sessionTime])
        {
     if (!MeetsCriteria(entry))
      continue;
     if (!selectedEntries.ContainsKey(currentEntryIndex++))
      continue;
     string timeStamp = entry.Timestamp.ToString("F", CultureInfo.CurrentCulture);
     string message = entry.Message;
     csvText.AppendFormat("\"{0}\",\"{1}\",\"{2}\"\n",
      timeStamp.Replace("\"", "\"\""), entry.Level.ToString(),
      message.Replace("\"", "\"\""));
     rawText.AppendFormat("{0}	{1}	{2}\n", timeStamp, entry.Level.ToString(),
      message);
        }
        if (csvText.Length > 0 || rawText.Length > 0)
        {
     DataObject tableText = new DataObject();
     tableText.SetText(rawText.ToString());
     byte[] bytes = Encoding.UTF8.GetBytes(csvText.ToString());
     MemoryStream tableStream = new MemoryStream(bytes);
     tableText.SetData(DataFormats.CommaSeparatedValue, tableStream);
     Clipboard.SetDataObject(tableText, true);
        }
 }
Exemple #21
0
 private void m_txtTrace_MouseDown(object sender, MouseEventArgs e)
 {
     DataObject data = new DataObject();
       data.SetText(m_txtTrace.Text);
       m_txtTrace.DoDragDrop( data, DragDropEffects.Copy);
 }
        internal static DataObject CreateHtmlFormatClipboardDataObject(string htmlFragment, string title = "From Clipboard", Uri sourceUri = null)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            // Builds the CF_HTML header. See format specification here:
            // http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/clipboard/htmlclipboard.asp

            // The string contains index references to other spots in the string, so we need placeholders so we can compute the offsets. 
            // The <<<<<<<_ strings are just placeholders. We'll backpatch them actual values afterwards.
            // The string layout (<<<) also ensures that it can't appear in the body of the html because the <
            // character must be escaped.
            string header =
    @"Version:0.9
StartHTML:<<<<<<<1
EndHTML:<<<<<<<2
StartFragment:<<<<<<<3
EndFragment:<<<<<<<4
";

            sb.Append(header);

            if (sourceUri != null)
            {
                sb.AppendFormat("SourceURL:{0}", sourceUri);
            }
            int startHtml = sb.Length;

            const string pre = @"<html><body>
<!--StartFragment-->";
            sb.Append(pre);
            int fragmentStart = sb.Length;

            sb.Append(htmlFragment);
            int fragmentEnd = sb.Length;

            const string post = @"<!--EndFragment-->
</body></html>";
            sb.Append(post);
            int endHtml = sb.Length;

            // Backpatch offsets
            sb.Replace("<<<<<<<1", To8DigitString(startHtml));
            sb.Replace("<<<<<<<2", To8DigitString(endHtml));
            sb.Replace("<<<<<<<3", To8DigitString(fragmentStart));
            sb.Replace("<<<<<<<4", To8DigitString(fragmentEnd));

            // Finally copy to clipboard.
            // http://stackoverflow.com/questions/13332377/how-to-set-html-text-in-clipboard
            string data = sb.ToString();
            var dataObject = new DataObject();
            dataObject.SetText(data, TextDataFormat.Html);
            dataObject.SetText(htmlFragment, TextDataFormat.Text);

            return dataObject;
        }
Exemple #23
0
		private void _copyToClipboardLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
#if MONO
//at least on Xubuntu, getting some rtf on the clipboard would mean that when you pasted, you'd see rtf
			if (!string.IsNullOrEmpty(_verboseBox.Text))
			{
				Clipboard.SetText(_verboseBox.Text);
			}
#else
			var data = new DataObject();
			data.SetText(_verboseBox.Rtf, TextDataFormat.Rtf);
			data.SetText(_verboseBox.Text, TextDataFormat.UnicodeText);
			Clipboard.SetDataObject(data);
#endif
		}
Exemple #24
0
 static void toolboxControl_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left )
         if (toolboxControl.SelectedItem != null)
         {
             System.Windows.Forms.DataObject obj = new DataObject();
             obj.SetText(toolboxControl.SelectedItem.ToString(), TextDataFormat.UnicodeText);
             obj.SetData(typeof(ScriptEditor).FullName + ".toolbox", toolboxControl);
             toolboxControl.DoDragDrop(obj, DragDropEffects.Copy | DragDropEffects.Move);
         }
 }
Exemple #25
0
 private void lvItems_MouseDown(object sender, MouseEventArgs e)
 {
     //Clipboard.SetDataObject(textBox1.Text);
     System.Collections.Specialized.StringCollection filePath = new
     System.Collections.Specialized.StringCollection();
     if (lvItems.SelectedItems.Count > 0) {
         filePath.Add(lvItems.SelectedItems[0].Text);
         DataObject dataObject = new DataObject();
         //dataObject.SetFileDropList(filePath);
         dataObject.SetText("testtesttest");
         dataObject.SetData("test");
         //dataObject.SetData("testtesttest");
         lvItems.DoDragDrop("test1111233", DragDropEffects.Move | DragDropEffects.Copy);
     }
 }
 private void CopyAsText(DataObject clipboardData)
 {
     StringBuilder text = new StringBuilder();
     text.AppendFormat("{0} Theme Manager Object: {1}\n",_selectedNodes.Count, (_selectedNodes.Count == 1) ? "" : "s");
     foreach (TmTreeNode node in _selectedNodes)
         text.AppendLine(node.TmNode.ToString());
     clipboardData.SetText(text.ToString());
 }
        private string CopyText(bool cut)
        {
            Control c = ActiveControl;
            ContainerControl cc = c as ContainerControl;

            while (cc != null)
            {
                c = cc.ActiveControl;
                cc = c as ContainerControl;
            }
            TextBoxBase tb = c as TextBoxBase;
            if (tb != null)
            {
                if (!tb.ReadOnly && tb.Enabled)
                {
                    string ret = tb.SelectedText;
                    if (cut)
                        tb.SelectedText = string.Empty;
                    return ret;
                }
                return null;
            }
            DataGridView dgv = c as DataGridView;
            if (dgv != null)
            {
                if (dgv.EditingControl != null)
                    return null;
                if (cut)
                {
                    if (dgv.BeginEdit(true))
                    {
                        if (dgv.EditingControl != null)
                        {
                            return CopyText(cut);
                        }
                    }
                }
                else if (object.ReferenceEquals(dgv, dataGridView1))
                {
                    if (dgv.SelectedRows.Count > 0)
                    {
                        if (dgv.CurrentCellAddress.Y >= 0 && dgv.CurrentCellAddress.Y < SelectedNodeKeyCount())
                        {
                            UInt64 id = GetRowKey(dgv.CurrentCellAddress.Y);
                            string keyname;
                            if (STBLVault.LookupKey(id, out keyname))
                                keyname = string.Format("\"{0}\"", keyname.Replace("\\", "\\\\").Replace("\"", "\\\""));
                            else
                                keyname = string.Format("0x{0:16X}", id);
                            string value = GetValueOf(dgv.CurrentCellAddress.Y);
                            string csvtext = string.Format("{0},\"{1}\"", keyname, value.Replace(@"\", @"\\").Replace("\"", "\\\""));
                            DataObject obj = new DataObject();
                            obj.SetText(csvtext, TextDataFormat.UnicodeText);
                            obj.SetText(csvtext, TextDataFormat.CommaSeparatedValue);
                            Clipboard.SetDataObject(obj);
                        }
                    }
                }
                else
                {
                    string text = dgv.CurrentCell.Value.ToString();
                    CopySimpleString(text);
                }
                return null;
            }
            return null;
        }
Exemple #28
0
		public bool Copy(bool run = true)
		{
			if (_selectedShapes.Count == 0)
				return false;
			if (run)
			{
				var buf = SerializeSelected();
				var data = new DataObject();

				data.SetData("DiagramDocument", buf.ToArray());

				var sortedShapes = _selectedShapes.OrderBy(s =>
				{
					var c = s.BBox.Center();
					return c.Y + c.X / 10;
				});
				var text = StringExt.Join("\n\n", sortedShapes
					.Select(s => s.PlainText()).Where(t => !string.IsNullOrEmpty(t)));
				if (!string.IsNullOrEmpty(text))
					data.SetText(text);

				// Crazy Clipboard deletes data by default on app exit!
				// need 'true' parameter to prevent loss of data on exit
				Clipboard.SetDataObject(data, true);
			}
			return true;
		}
Exemple #29
0
 private void DraggableIcon_ItemDrag(object sender, ItemDragEventArgs e)
 {
     try
     {
         using (var tsf = new TemporarySaveFile(this))
         {
             DataObject obj = new DataObject();
             if (DraggableIcon.Items[0].Text.StartsWith("text/"))
             {
                 string data_ = new StreamReader(tsf.data).ReadToEnd();
                 obj.SetText(data_, DraggableIcon.Items[0].Text == "text/html" ? TextDataFormat.Html : TextDataFormat.UnicodeText);
             }
             else if (DraggableIcon.Items[0].Text.StartsWith("image/"))
             {
                 var data_ = new Bitmap(tsf.data);
                 obj.SetImage(data_);
             }
             else
                 obj.SetData(tsf.data);
             tsf.data.Close();
             obj.SetData(DataFormats.FileDrop, true, new String[] { tsf.tempfilename });
             disable_scrolling = true;
             try
             {
                 DraggableIcon.DoDragDrop(obj, DragDropEffects.All);
             }
             finally
             {
                 disable_scrolling = false;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, "Error when dragging file: " + ex.ToString(), "Error from BEurtle", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #30
0
		//-------------------------------------------------------------------------------------
		/// <summary>
		/// 
		/// </summary>
		/// <param name="keyData"></param>
		/// <returns></returns>
		protected override bool ProcessDialogKey(Keys keyData)
		{
			if(keyData == Keys.Back)
			{
				KeyPressEventArgs e = new KeyPressEventArgs((char)keyData);
				OnKeyPress(e);
				if(e.Handled)
					return true;
			}
			else if(keyData == (Keys.Shift|Keys.Add))
			{
				if(this.SelectedNode == null)
					return true;
				this.BeginUpdate();
				this.SelectedNode.ExpandAll();
				this.EndUpdate();
				return true;
			}
			else if(keyData == (Keys.Shift|Keys.Subtract))
			{
				if(this.SelectedNode == null)
					return true;
				this.BeginUpdate();
				this.SelectedNode.Collapse(false);
				this.EndUpdate();
				return true;
			}
			else if(keyData == (Keys.Control|Keys.Add))
			{
				this.BeginUpdate();
				this.ExpandAll();
				this.EndUpdate();
				return true;
			} 
			else if(keyData == (Keys.Control|Keys.Subtract))
			{
				this.BeginUpdate();
				this.CollapseAll();
				if(this.Nodes.Count >0)
						this.Nodes[0].Expand();
				this.EndUpdate();
				return true;
			}
			else if(keyData == (Keys.Control|Keys.C))
			{
				string val = null;
				if(this.SelectedNode != null)
					val = this.SelectedNode.Text;

				DataObject obj = new DataObject();
				obj.SetText(val, TextDataFormat.UnicodeText);
				obj.SetText(val, TextDataFormat.Text);
				Clipboard.SetDataObject(obj, true);
				return true;
			} 

			return base.ProcessDialogKey(keyData);
		}
        private static void CopySimpleString(string name)
        {
            if (string.IsNullOrEmpty(name))
                return;

            DataObject obj = new DataObject();
            obj.SetText(name, TextDataFormat.UnicodeText);
            bool isascii = true;
            for (int loop = 0; loop < name.Length; loop++)
            {
                if (name[loop] >= 128)
                    isascii = false;
            }
            if (isascii)
                obj.SetText(name, TextDataFormat.Text);
            Clipboard.SetDataObject(obj);
        }