You WinListView DragDrop demo is a very terrible example when displaying elements being dragged. If I select like three items that are going to be dragged that are far apart from each other in the list view these items remain far apart from each other while being dragged. These items should be directly right underneath each other while being dragged not half way spread out away from each other. Do you have a fix for this in you demo.
Hello ,
As far as I understand you want to “rearrange the icons” in the image which is displayed when the “Drag” operation starts. In the sample, which you mentioned this icons are drawing with their relative coordinates (actually they are drawing with their locations and sizes onto a bitmap ) that's why the elements are dragged so far from each other. Also this functionality is not embedded into the component, which mean that the developer is responsible for its implementation. Based on this, order of icons is designer’s decision and any kind of ordering should be consider as a correct. In the sample which you mentioned, the code which is responsible for displaying of this icons, when the “Drag” operation starts, is in “DragDropManager” class find “DragImageManager” class, “Methods” region, “CreateDragImage” region, CreateDragImage method. So you could modify this method based on your needs. One possible modification could be the following:
#region CreateDragImage
/// <summary>
/// Generates the image that is displayed to depict the contents of the drag operation.
/// </summary>
/// <param name="dragElements">An array of UIElements from which the image is generated.</param>
private void CreateDragImage( UIElement[] dragElements )
{
if ( dragElements == null || dragElements.Length == 0 )
return;
// Calculate the bounds of a rectangle which contains all the elements
int left = short.MaxValue, top = short.MaxValue, right = 0, bottom = 0;
for ( int i = 0; i < dragElements.Length; i ++ )
UIElement element = dragElements[i];
if ( element == null )
continue;
Rectangle elementRect = element.Rect;
left = Math.Min( left, elementRect.Left );
top = Math.Min( top, elementRect.Top );
right = Math.Max( right, elementRect.Right );
bottom = Math.Max( bottom, elementRect.Bottom );
}
Point renderingOffset = new Point( left, top );
Size size = new Size( right - left, bottom - top );
Rectangle bounds = new Rectangle( Point.Empty, size );
// Create the Bitmap which we will draw on to create the drag image
this._dragImage = new Bitmap( size.Width, size.Height );
Bitmap img = new Bitmap( size.Width, size.Height );
Graphics gr = null;
Graphics grHelper = null;
Matrix matrix = null;
try
// Create a Graphics object from the Bitmap we created above;
// fill it with the transparent color and offset its rendering origin.
gr = Graphics.FromImage( this._dragImage );
grHelper = Graphics.FromImage( img );
// Transform the coordinate system to shift the point of origin
matrix = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, renderingOffset.X * -1, renderingOffset.Y * -1 );
gr.Transform = matrix;
grHelper.Transform = matrix;
// Get the BackColor of the parent form...we need to use this as the background color
// because when we draw the UIElements to the Graphics object, transparent areas will
// be drawn with this color, and we want those areas to be masked out of the resulting image.
Color parentFormBackColor = dragElements[0] != null ? dragElements[0].Control.BackColor : Form.DefaultBackColor;
gr.Clear( parentFormBackColor );
grHelper.Clear(parentFormBackColor);
// Draw each element onto the Graphics object
Point location = new Point(1,1);
if (location.X == -1)
location = element.Rect.Location;
Rectangle rect = new Rectangle(location, element.Rect.Size);
Debug.WriteLine(string.Format("el rect{0}, my rect {1}", element.Rect, rect));
element.Draw(grHelper, element.Rect, true, AlphaBlendMode.Disabled);
gr.DrawImage(CropImage(img, element.Rect), location);
location.Offset(10,10);
// Generate a Region from the Bitmap we just created above
this._dragImageRegion = ImageManager.CreateBitmapRegion( this._dragImage, parentFormBackColor );
// Adjust the opacity of the drag image to give it
// a semi-transparent, "ghosted" appearance.
this.AdjustTransparency( this._dragImage );
finally
// Dispose of the Graphics and Matrix objects
if ( gr != null )
gr.Dispose();
if (grHelper != null)
grHelper.Dispose();
if ( matrix != null )
matrix.Dispose();
public Bitmap CropImage(Bitmap source, Rectangle section)
// An empty bitmap which will hold the cropped image
Bitmap bmp = new Bitmap(section.Width, section.Height);
Graphics g = Graphics.FromImage(bmp);
// Draw the given area (section) of the source image
// at location 0,0 on the empty bitmap (bmp)
g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
return bmp;
#endregion CreateDragImage
Thank you for using Infragistics Components.
You really did not answer the question I asked. All you did is pasted posted code. I already saw that code. I tried modifying the rectangle cordinated in the element.Draw method so the elements would be right underneath each other but only the fist item was displayed in the drag image. As shown blow are the parts of the code I modified.
The first for loop creates the exact size for the bitmap need.
The second for loop draws each item in the bitmap with each successive item appearing under the prior.
But when I drag the times only the first item appears
foreach (var elementRect in from element in dragElements where element != null select element.Rect)
left =
Math.Min(top, elementRect.Top);
right =
Math.Max(right, elementRect.Right);
// bottom =Math.Max(bottom, elementRect.Bottom);
bottom += elementRect.
Height;//Math.Max(bottom, elementRect.Bottom);
top =
Math.Min(left, elementRect.Left);
int counter = 0;
Rectangle rect = new Rectangle(left, top, 0, 0);
foreach (UIElement element in dragElements)
if (element == null)
rect.
Y = top + counter*element.Rect.Height;
Width = element.Rect.Width;
Height = element.Rect.Height;
element.
Draw(gr, rect, true, AlphaBlendMode.Disabled);
// element.Draw(gr, element.Rect, true, AlphaBlendMode.Disabled);
counter++;
Your code does not work.
I tried it in the demo and there are no items displayed when dragging