Click here to Skip to main content
13,042,819 members (74,679 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 31 Jan 2014

Drag and Drop from Custom Task Pane to Microsoft Office Documents

, 31 Jan 2014
Rate this:
Please Sign up or sign in to vote.
This tip briefly explains drag and drop text from custom task pane to Excel\Word\Powerpoint


Have you ever needed a text to be dragged and dropped into Office documents from your custom task pane? If yes, go ahead.


In this tip, I refer to Excel, Word and Powerpoint 2010 as Office documents. Basically, Office documents allow drag and drop (D&D) content within the applications, across the Office applications and from other text editors like Wordpad, Microsoft Visual Studio, etc.

My previous article ResizeCustomTaskPane states the prerequisites that user should know before implementing this tip. Let us see simple D&D text from custom task pane.

Using the Code

Architecture and source code are the same as my previous article and to save time, I have explained only the heart of the code. Refer to the following image of this sample.

The taskpane has 4 buttons and all the button's mousedown events are hooked to a single function.

private void button1_MouseDown(object sender, MouseEventArgs e)    {
            if (MouseButtons == MouseButtons.Left)
                string strValue = "I am " + (sender as Button).Text;
                if (OfficeType == OfficeAPPType.EXCEL || OfficeType == OfficeAPPType.WORD)
                                    (sender as Button).DoDragDrop(strValue, DragDropEffects.All);
                                else if (OfficeType == OfficeAPPType.PPT)
                                    if (m_rich == null)
                                        m_rich = new RichTextBox();
                    m_rich.Text = strValue;
                    IDataObject data = new DataObject();
                                        data.SetData(DataFormats.Rtf, m_rich.Rtf);
                    (sender as Button).DoDragDrop(data, DragDropEffects.All);                    

D&D for Powerpoint is little trickier than Excel and Word. Both Excel and Word support DataFormats.Text, so we can directly supply string value to DoDragDrop function. Powerpoint needs DataFormats.Rtf format, so supply IDataObject with RTF text. Here I used RichTextBox to get the RTF text. That's all we need to drag and drop the text from taskpane. Ideas better than this are always welcome.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionSource Code Empty Pin
Member 958330924-Oct-15 5:12
memberMember 958330924-Oct-15 5:12 
AnswerRe: Source Code Empty Pin
Sivaji156525-Oct-15 20:11
memberSivaji156525-Oct-15 20:11 
BugUnable to test: broken licenses.licx Pin
Gustavo Miller29-Apr-14 2:43
memberGustavo Miller29-Apr-14 2:43 
GeneralRe: Unable to test: broken licenses.licx Pin
Sivaji156529-Apr-14 19:13
memberSivaji156529-Apr-14 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 31 Jan 2014
Article Copyright 2014 by Sivaji1565
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid