By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

How to draw object moving during drag n drop?

P: n/a
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);
}
Sep 6 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.