/// <summary> /// Extracts data of type <c>Dataformat.Html</c> from an <c>IDataObject</c> data container /// This method shouldn't throw any exception but writes relevant exception informations in the debug window /// </summary> /// <param name="data">data container</param> /// <returns>A byte[] array with the decoded string or null if the method fails</returns> /// <remarks>Added 2006-06-12, <c>Uwe Keim</c>.</remarks> private static byte[] getHtml( IDataObject data) { var interopData = (System.Runtime.InteropServices.ComTypes.IDataObject)data; var format = new FORMATETC { cfFormat = ((short)DataFormats.GetFormat(DataFormats.Html).Id), dwAspect = DVASPECT.DVASPECT_CONTENT, lindex = (-1), tymed = TYMED.TYMED_HGLOBAL }; STGMEDIUM stgmedium; stgmedium.tymed = TYMED.TYMED_HGLOBAL; stgmedium.pUnkForRelease = null; var queryResult = interopData.QueryGetData(ref format); if (queryResult != 0) { return(null); } interopData.GetData(ref format, out stgmedium); if (stgmedium.unionmember == IntPtr.Zero) { return(null); } var pointer = stgmedium.unionmember; var handleRef = new HandleRef(null, pointer); byte[] rawArray; try { var ptr1 = GlobalLock(handleRef); var length = GlobalSize(handleRef); rawArray = new byte[length]; Marshal.Copy(ptr1, rawArray, 0, length); } finally { GlobalUnlock(handleRef); } return(rawArray); }
private DirectoryObject[] ProcessSelections(System.Runtime.InteropServices.ComTypes.IDataObject dataObj) { const string ClipboardFormat = "CFSTR_DSOP_DS_SELECTION_LIST"; if (dataObj == null) { return(null); } DirectoryObject[] result = null; STGMEDIUM stg; var fe = new FORMATETC { cfFormat = (short)DataFormats.GetFormat(ClipboardFormat).Id, ptd = IntPtr.Zero, dwAspect = DVASPECT.DVASPECT_CONTENT, lindex = -1, tymed = TYMED.TYMED_HGLOBAL }; dataObj.GetData(ref fe, out stg); var dsSelectionList = Memory.NativeMethods.GlobalLock(stg.unionmember); if (dsSelectionList == IntPtr.Zero) { NativeMethods.ReportWin32Exception(); } try { var current = dsSelectionList; var count = Marshal.ReadInt32(current); var fetchedAttributesCount = Marshal.ReadInt32(current, Marshal.SizeOf(typeof(uint))); if (count > 0) { result = new DirectoryObject[count]; current += Marshal.SizeOf(typeof(uint)) * 2; for (var i = 0; i < count; i++) { var selection = (DSSelection)Marshal.PtrToStructure(current, typeof(DSSelection)); result[i] = new DirectoryObject(selection.pwzName, selection.pwzADsPath, selection.pwzClass, selection.pwzUPN, GetFetchedAttributes(selection.pvarFetchedAttributes, fetchedAttributesCount, selection.pwzClass)); current += Marshal.SizeOf(typeof(DSSelection)); } } } finally { Memory.NativeMethods.GlobalUnlock(dsSelectionList); COM.NativeMethods.ReleaseStgMedium(ref stg); } return(result); }
//編集メニュー項目内のマスク処理 private void EditMaskCheck() { DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Rtf); UndoToolStripMenuItem.Enabled = rtTextArea.CanUndo ? true : false; RedoToolStripMenuItem.Enabled = rtTextArea.CanRedo ? true : false; CutToolStripMenuItem.Enabled = rtTextArea.SelectionLength > 0 ? true : false; CopyToolStripMenuItem.Enabled = rtTextArea.SelectionLength > 0 ? true : false; DeleteToolStripMenuItem.Enabled = rtTextArea.SelectionLength > 0 ? true : false; PasteToolStripMenuItem.Enabled = rtTextArea.CanPaste(myFormat) ? true : false; }
public void DataFormats_GetFormat_InvokeKnownString_ReturnsExpected(string format, string expectedName, int expectedId) { DataFormats.Format result = DataFormats.GetFormat(format); Assert.Same(result, DataFormats.GetFormat(format.ToLower())); Assert.Equal(expectedName, result.Name); Assert.Equal(expectedId, result.Id); // Call again to test caching behavior. Assert.Same(result, DataFormats.GetFormat(format)); }
//在richbox 上放圖片 private void richTextBoxImage(int i, string path) { Clipboard.SetDataObject(this.imageList1.Images[i]); DataFormats.Format dataFormat = DataFormats.GetFormat(DataFormats.Bitmap); if (richTextBox1.CanPaste(dataFormat)) { richTextBox1.Text = path; richTextBox1.Paste(dataFormat); } }
private void contextMenuStripExpress_Opening(object sender, CancelEventArgs e) { evaluateToolStripMenuItem.Enabled = richExpression.TextLength > 0; cutToolStripMenuItem.Enabled = richExpression.SelectionLength > 0; copyToolStripMenuItem.Enabled = richExpression.SelectionLength > 0; pasteToolStripMenuItem.Enabled = richExpression.CanPaste(DataFormats.GetFormat(DataFormats.Text)); clearToolStripMenuItem.Enabled = richExpression.TextLength > 0; selectallToolStripMenuItem.Enabled = richExpression.CanSelect && richExpression.TextLength > 0; topmostToolStripMenuItem.Checked = this.TopMost; }
public static void Copy(object o, Type type) { // serialize object to clipboard DataFormats.Format format = DataFormats.GetFormat(type.FullName); IDataObject dataObj = new DataObject(); dataObj.SetData(format.Name, false, o); System.Windows.Forms.Clipboard.SetDataObject(dataObj, false); }
/* * Копировать - Вставить - Вырезать */ #region protected virtual void CopyToClipboard() protected virtual void CopyToClipboard() { // регистрация формата данных либо получаем его, если он уже зарегистрирован var format = DataFormats.GetFormat(typeof(T[]).FullName); // копируем в буфер обмена IDataObject dataObj = new DataObject(); dataObj.SetData(format.Name, false, SelectedItems.ToArray()); Clipboard.SetDataObject(dataObj, false); }
private void textBoxComment_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.V) { if (textBoxComment.CanPaste(DataFormats.GetFormat(DataFormats.Bitmap))) { e.SuppressKeyPress = true; } } }
private void rtbTarget_KeyDown(object sender, KeyEventArgs e) { // キーボードペースト if (e.Control == true && e.KeyCode == Keys.V) { // テキストフォーマットで貼り付け rtbTarget.Paste(DataFormats.GetFormat(DataFormats.Text)); e.Handled = true; } }
private void miPaste_Click(object sender, EventArgs e) { RichTextBox rtb = WindowsAPI.GetFocusedControl() as RichTextBox; if (rtb != null) { rtb.Paste(DataFormats.GetFormat(DataFormats.Text)); } RefreshUI(); }
void UpdateEditMenu() { if (_richTextBox != null) { _miRtfEditUndo.Enabled = _richTextBox.CanUndo; _miRtfEditCut.Enabled = CanDelete; _miRtfEditCopy.Enabled = CanDelete; _miRtfEditPaste.Enabled = _richTextBox.CanPaste(DataFormats.GetFormat(DataFormats.Rtf)); _miRtfEditDelete.Enabled = CanDelete; } }
//---------------------------------------------------------------------------------------------------------------- private void SetIcons() { chatTextBox.ReadOnly = false; Bitmap bitmap = new Bitmap(pictureBox1.Image, new Size(20, 20)); Clipboard.SetImage(bitmap); DataFormats.Format format = DataFormats.GetFormat(DataFormats.Bitmap); chatTextBox.Paste(format); Clipboard.Clear(); }
private void pasteMenuItem_Click(object sender, EventArgs e) { bool c = CancelRefillTask(); String serializedData = (String)Clipboard.GetData(DataFormats.GetFormat(formatName).Name); FireElementsImported(serializedData, Grid.RowCount); if (c) { StartRefillTask(); } }
/// <summary> /// Copies the suite object to clipboard. /// </summary> public static void CopyToClipboard(T objectToCopy) { // register my custom data format with Windows or get it if it's already registered DataFormats.Format format = DataFormats.GetFormat(typeof(T).FullName); // now copy to clipboard IDataObject dataObj = new DataObject(); dataObj.SetData(format.Name, false, objectToCopy); Clipboard.SetDataObject(dataObj, false); }
private void fileToolStripMenuItem_DropDownOpening(object sender, EventArgs e) { var hasText = codeEditor.TextLength > 0; saveToolStripMenuItem.Enabled = hasText && !string.IsNullOrEmpty(lastFileName); saveAsToolStripMenuItem.Enabled = printToolStripMenuItem.Enabled = hasText; undoToolStripMenuItem.Enabled = codeEditor.CanUndo; redoToolStripMenuItem.Enabled = codeEditor.CanRedo; cutToolStripMenuItem.Enabled = copyToolStripMenuItem.Enabled = codeEditor.SelectionLength > 0; pasteToolStripMenuItem.Enabled = codeEditor.CanPaste(DataFormats.GetFormat(DataFormats.Text)); }
public static FORMATETC CreateFormat(string format) { return(new FORMATETC { tymed = SupportedTymed, cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id)), dwAspect = DVASPECT.DVASPECT_CONTENT, lindex = -1, ptd = IntPtr.Zero }); }
private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { if (customRTB.Focused == true) { customRTB.Paste(DataFormats.GetFormat(DataFormats.Text)); } else { searchTextBox.Paste(); } }
/// <summary> /// Hiển thị ảnh với tỉ lệ thu nhỏ /// </summary> /// <param name="fullName"></param> private void DisplayImage(string fullName, double percent) { Image myImage = Image.FromFile(fullName); myImage = ResizeImage(myImage, percent); System.Drawing.Image tempImage = myImage; Clipboard.SetDataObject(tempImage); DataFormats.Format image = DataFormats.GetFormat(DataFormats.Bitmap); khungHienThi.Paste(image); }
private void mitCopy_Click(object sender, System.EventArgs e) { DataFormats.Format myFormat = DataFormats.GetFormat("demoSerialisation"); MemoryStream mem = new MemoryStream(); SerializationHelper.Serialize(gtv, mem, gtv.SelectedNode, false); DataObject myDataObject = new DataObject(myFormat.Name, mem); Clipboard.SetDataObject(myDataObject); }
public ScenarioResult Get_Format_By_Id(TParams p) { DataFormats.Format formatObj; int iFormat = Get_DataFormat_Int(p); p.log.WriteLine("Format type number : " + iFormat); formatObj = DataFormats.GetFormat(iFormat); return(new ScenarioResult(formatObj.Id == iFormat, "Unexpected format type : " + formatObj.Id)); }
public ScenarioResult Get_Format_By_String(TParams p) { DataFormats.Format formatObj; string strFormat = Get_DataFormat_String(p); p.log.WriteLine("Format type : " + strFormat); formatObj = DataFormats.GetFormat(strFormat); return(new ScenarioResult(Verify_Format_Type(formatObj.Name, strFormat), "Unexpected format type : " + formatObj.Name)); }
void FullCopy() { DataFormats.Format format = DataFormats.GetFormat("mhdEffectBIN"); MemoryStream memoryStream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memoryStream); myFX.StoreTo(ref writer); writer.Close(); Clipboard.SetDataObject(new DataObject(format.Name, memoryStream.GetBuffer())); memoryStream.Close(); }
private void rtbContextMenuStrip_Opening(object sender, CancelEventArgs e) { cutContextMenuItem.Enabled = rtbClassGenerator.SelectionLength > 0 ? true : false; copyContextMenuItem.Enabled = cutContextMenuItem.Enabled; clearContextMenuItem.Enabled = cutContextMenuItem.Enabled; undoContextMenuItem.Enabled = rtbClassGenerator.CanUndo; redoContextMenuItem.Enabled = rtbClassGenerator.CanRedo; pasteContextMenuItem.Enabled = rtbClassGenerator.CanPaste(DataFormats.GetFormat(DataFormats.Text)); }
private static void CopyToClipboard <T>(T obj) { Debug.Assert(obj != null, "Cannot copy null to clipboard"); if (obj != null) { var copyDataObject = new DataObject(); var t = typeof(T); copyDataObject.SetData(DataFormats.GetFormat(t.FullName).Name, obj); Clipboard.SetDataObject(copyDataObject); } }
private void btn21_Click(object sender, EventArgs e) { Bitmap img = new Bitmap(btn21.BackgroundImage); Clipboard.Clear(); Clipboard.SetDataObject(img); DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap); rtbWriteMsg.Paste(myFormat); panel1.Visible = false; img.Dispose(); }
/// <summary> /// Set Object with type Type to the clipboard /// </summary> /// <param name="type">Type</param> /// <param name="obj">object</param> public static void SetClipboardData(Type type, Object obj) { DataFormats.Format format = DataFormats.GetFormat(type.FullName); //now copy to clipboard IDataObject dataObj = new DataObject(); dataObj.SetData(format.Name, false, obj); // Use false to make the object dissapear when the application stops. SetDataObject(dataObj, true); }
/// <summary> /// ¿½±´µ½¼ôÌù°å /// </summary> public void CopyToClipboard() { DataFormats.Format format = DataFormats.GetFormat(typeof(SnipData).FullName); //now copy to clipboard IDataObject dataObj = new DataObject(); dataObj.SetData(format.Name, false, this); Clipboard.SetDataObject(dataObj, true); }
public static void CopyToClipboard <T>(T objectToCopy) where T : class { var format = DataFormats.GetFormat(typeof(T).FullName); currentObject = objectToCopy; var dataObject = new DataObject(); dataObject.SetData(format.Name, false, "NeoAxis.ClipboardManager"); Clipboard.SetDataObject(dataObject, false); }
//編集メニュー項目内のマスク処理 private void EditEToolStripMenuItem_Click(object sender, EventArgs e) { DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Rtf); UndoUToolStripMenuItem.Enabled = rtTextArea.CanUndo; RedoRToolStripMenuItem.Enabled = rtTextArea.CanRedo; CutoutTToolStripMenuItem.Enabled = rtTextArea.SelectionLength > 0; CopyCToolStripMenuItem.Enabled = rtTextArea.SelectionLength > 0; //PastingPToolStripMenuItem.Enabled = rtTextArea.CanPaste(myFormat) ? true : false; PastingPToolStripMenuItem.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Rtf); DeleteToolStripMenuItem.Enabled = rtTextArea.SelectionLength > 0; }