Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / August 2004

Tip: Looking for answers? Try searching our database.

Cut/Copy/Paste Forms Designer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 19 Aug 2004 21:20 GMT
I'm creating a custom forms designer by using IDesignerHost to host
components.  Adding components from a toolbox works fine and as
expected.  I'm trying to add other actions though - like Cut, Copy and
Paste (and Undo/Redo too).  I've already implemented Delete - by just
using StandardCommands.Delete.  However, StandardCommands.Cut, etc do
nothing.

How do I cut, copy and paste controls?

Thanks.
"Jeffrey Tan[MSFT]" - 20 Aug 2004 07:40 GMT
Hi Mike,

Normally, the cut operation is implemented through invoking both Copy and
Delete operation. You may place these 2 operations in a
DesignerTransaction, then you may cancel the cut operation when user uses
"undo". Sample like this:
private void OnMenuCut(object sender, EventArgs e)
{
    IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
    if (host != null && m_currentSelection != null && m_currentSelection.Count
> 0)
    {
        using(DesignerTransaction trans = host.CreateTransaction("Cut " +
m_currentSelection.Count + " component(s)"))
        {
            OnMenuCopy(sender, e);
            OnMenuDelete(sender, e);
            trans.Commit();
        }
    }
}

For the copy operation, we may leverage VS.net designer's
IDesignerSerializationService to serialize the selected components into an
object, then wrap the object through DataObject class, at last place it
into clipboard. Sample like this:
private void OnMenuCopy(object sender, EventArgs e)
{
    IDesignerSerializationService ds =
(IDesignerSerializationService)GetService(typeof(IDesignerSerializationServi
ce));
    if (ds != null)
    {
        object serializedData = ds.Serialize(m_currentSelection);
        DataObject data = new DataObject("ShapeLibraryData", serializedData);
        Clipboard.SetDataObject(data, true);
    }
}

For the delete operation, we may also loop through the selected components
collection, then use IDesignerHost.DestroyComponent method to delete them.

For more information, please refer to the below article, it contains the
source code for all the function and is a good resource for learning
design-time issue:
".NET Shape Library: A Sample Designer"
http://windowsforms.net/articles/shapedesigner.aspx

======================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.