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);
}