PC Review


Reply
Thread Tools Rate Thread

How to draw object moving during drag n drop?

 
 
=?Utf-8?B?TXJOb2JvZHk=?=
Guest
Posts: n/a
 
      6th Sep 2006
I have a custom Panel which will have smaller custom Panels added and drawn
within it. I want to be able to re-order the arrangement of the inner Panels
using drag n drop, and I want to do this graphically by actually drawing the
inner Panel being dragged around, instead of just the default DragDropEffects
graphics.

But I can't seem to get this to work...

What I tried is when you click on an inner Panel you acitvate a DragNDrop
with the panel itself being the Data object. Then in the DragOver event of
the main, outer panel I pull out the inner Panel object and assign it a new
Location, to where the current mouse x,y are. Then I tried calling Refresh
on either and/or both the outer panel and inner panel to no success.

What happens is the inner Panel is drawn initially then as soon as I click
on it to drag it, it disappears and as I drag my mouse over the outer panel
it is never redrawn again.

Any suggestions?

Here's some code...

Within InnerPanel:

void InnerPanel_MouseDown(object sender, MouseEventArgs e)
{
this.DoDragDrop(this, DragDropEffects.Move);
}

Within OuterPanel:

// AllowDrop set to true

void OuterPanel_DragOver(object sender, DragEventArgs e)
{

InnerPanel i = e.Data.GetData(typeof(InnerPanel)) as InnerPanel;
i.Location = new Point(e.X, e.Y);
//this.Refresh(); //tried refreshing outer panel
//i.Refresh(); //also tried refreshing just inner panel
}

InnerPanel has a overriden OnPaint which basically just draws itself as a
roudned ractangle with a thick border. nothing fancy or crazy. It uses an
ExtendedGraphics object to do the rounded rectangle- something someone else
wrote on the Net somewhere

protected override void OnPaint(PaintEventArgs args)
{
Graphics gfx = args.Graphics;

gfx.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

Pen myPen = new Pen(borderColor);
myPen.Width = 2;
ExtendedGraphics egfx = new ExtendedGraphics(gfx);

Brush brush = Brushes.DarkCyan;

egfx.FillRoundRectangle(brush, 0, 0, this.Width-2,
this.Height-2, 10);
egfx.DrawRoundRectangle(myPen, 0, 0, this.Size.Width-2,
this.Height-2, 10);
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drag and drop copies instead of moving 325bessererstreet@gmail.com Windows XP Help 2 1st Apr 2007 01:44 AM
Draw a line between 2 list boxes using drag and drop... murl Microsoft VB .NET 2 4th Feb 2004 09:42 PM
Moving a control at runtime via drag and drop =?Utf-8?B?Sm9lIFRob21wc29u?= Microsoft Dot NET Framework Forms 1 27th Jan 2004 04:01 PM
TreeView/HatchBrush: weird interaction [Was Re: Straightforward way to draw lines between tree nodes during drag & drop?] Eric Promislow Microsoft Dot NET Framework Forms 0 11th Sep 2003 09:26 PM
Straightforward way to draw lines between tree nodes during drag & drop? Eric Promislow Microsoft Dot NET Framework Forms 0 5th Aug 2003 10:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:12 PM.