Answered by:
Windows Form Drag Control

Question
-
Hi Everybody
I got a problem, I'm develop a Windows Form application that contain a panel and in the panel I'll add user controls that are be able to move with the mouse, that part is working perfect.
But when I put a background image to the panel then every time a move the control the image start to erase where the control is move, after stop moving the control then the image reload again
Is there a way to avoid that the image does that?
Thanks
- Edited by jics21 Thursday, September 3, 2015 4:30 PM
Answers
-
Hi
Thanks for the replay
I found a solution, I just need to use double-buffering to reduce the amount of flickering when re-drawing
Thanks for your responses.
- Proposed as answer by DotNet Wang Tuesday, September 15, 2015 8:58 AM
- Marked as answer by Kristin Xie Tuesday, September 15, 2015 9:47 AM
All replies
-
-
Hi I put the update for the panel and the erase effect is less but still hapen
here is the code for the move
void control_MouseMove(object sender, MouseEventArgs e)
{
if (drag && e.Button == System.Windows.Forms.MouseButtons.Left)
{
Parent.Update();
System.Drawing.Point newLocationOffset = e.Location - mouseOffset;
#region X
if (this.Left + newLocationOffset.X <= Parent.Location.X)
{
this.Left = Parent.Location.X;
}
else if (this.Left + this.Width + newLocationOffset.X >= Parent.Width)
{
this.Left = Parent.Width - this.Width;
}
else
{
this.Left += newLocationOffset.X;
}
#endregion
#region Y
if (this.Top + newLocationOffset.Y <= 0)
{
this.Top = 0;
}
else if (this.Top + this.Height + newLocationOffset.Y >= Parent.Height)
{
this.Top = Parent.Height - this.Height;
}
else
{
this.Top += newLocationOffset.Y;
}
#endregion
}
}
-
Those are details of how redrawing, caching and whatnot work. This really should be asked in teh WinForms subforum. It is way beyond a simple C# question.
A simple solution might be not to actually drag the Element around. Rather drag a primitive "shadow" around that helps users guessing the new layout and only move on mouse release.
Could it be you are looking for a Docking Control? That is the same type of layout used for Visual Studio itself. As far as I know for that you need 3rd party libraries. Not even WPF has a native Docking Layout Control.
http://www.telerik.com/help/winforms/dock-architecture-and-features-understanding-raddock.html
http://www.codeproject.com/Articles/18812/WPF-Docking-Library
-
Hi
Thanks for the replay
I found a solution, I just need to use double-buffering to reduce the amount of flickering when re-drawing
Thanks for your responses.
- Proposed as answer by DotNet Wang Tuesday, September 15, 2015 8:58 AM
- Marked as answer by Kristin Xie Tuesday, September 15, 2015 9:47 AM