GetDragHintCore is not called

3 posts, 1 answers
  1. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 22 Feb 2012 Link to this post

    I have a custom VisualItem (class CustomVisualItem : IconListViewVisualItem) and I want a nice image of this item while dragging.
    So I wrote this in my VisualItem, but this method never get called (no message in output).
    protected override Image GetDragHintCore()
           {
              Debug.WriteLine("GetDragHintCore");
              return GetAsBitmap(Brushes.Yellow, 2, new SizeF(48, 48));      
           }

    Is it a bug or my fault?
    Ps: There is pretty much no docu on these to methods (GetDragHintCore and GetAsBitmap [what about the parameters?]).

  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 24 Feb 2012 Link to this post

    Hi Froggie,

    Thank you for writing.

    The GetDragHintCore is used by the built-in drag drop system and as far as I am aware from your previous threads, you are using the default drag-drop system that the .NET framework provides. That is why it does not get called. The GetAsBitmap method of RadElement returns a snapshot of its element as an Image so it can be used to achieve the desired functionality with the default drag-drop mechanism. The following code snippet demonstrates this:
    Cursor dragCursor;
     
    void radListView1_GiveFeedback(object sender, GiveFeedbackEventArgs e)
    {
        e.UseDefaultCursors = false;
        Cursor.Current = dragCursor;
    }
     
    private void radListView1_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = e.Data.GetDataPresent(typeof(ListViewDataItem)) ? DragDropEffects.Move : DragDropEffects.None;
        if(e.Effect == DragDropEffects.Move)
            Drawcursor(e);
    }
     
    public static Bitmap SetOpacity(Bitmap original, float opacity)
    {
        Bitmap temp = new Bitmap(original.Width, original.Height);
        Graphics g = Graphics.FromImage(temp);
        ColorMatrix cm = new ColorMatrix();
        cm.Matrix33 = opacity;
     
        ImageAttributes ia = new ImageAttributes();
        ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        g.DrawImage(original, new Rectangle(0, 0, temp.Width, temp.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia);
        g.Dispose();
     
        return temp;
    }
     
    public void Drawcursor(DragEventArgs e)
    {
        if (e.Data == null)
            return;
        ListViewDataItem item = e.Data.GetData(typeof(ListViewDataItem)) as ListViewDataItem;
        if (item == null)
            return;
     
        RadElement element = this.radListView1.ListViewElement.ViewElement.GetElement(item);
        Bitmap bmp = SetOpacity(element.GetAsBitmapEx(Color.Transparent, 0, new SizeF(1, 1)), 0.5f);
        dragCursor = new Cursor(bmp.GetHicon());
        bmp.Dispose();
    }

    As to your notice about the documentation, we are aware that a part of our publicly accessible API is not well documented and we are constantly working on improving it.

    Thank you for your feedback. Should you have any further questions, feel free to write back.

    Regards,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 24 Feb 2012 Link to this post

    Thank you!
    That solution works like a charm.
    Right now I'm testing this solution when scrolling while dragging.
Back to Top