This is a migrated thread and some comments may be shown as answers.

Panorama DragDrop animation

3 Answers 119 Views
Panorama
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 14 Dec 2015, 04:06 PM

Hi,

I would like know if it's possible to disable the reposition's animation of all tiles after the DragDrop action?

Does it exist an event at the end of the DragDrop animation ? Because after the event DragDropService.Stopped I can see that my tiles are still animated.

 Thanks for your help.

Simon

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Dec 2015, 09:35 AM
Hello Simon,

Thank you for writing.
 
Note that RadPanorama uses its TileDragDropService to perform drag and drop operation. In the TileDragDropService.PrepareContext method, AnimatedPropertySetting is applied to the tiles manipulating the offset and the scale transform. You can prevent this functionality by using a custom TileDragDropService. You should suspend animations of RadPanorama as well: 
public Form1()
{
    InitializeComponent();
    this.radPanorama1.PanoramaElement.ElementTree.SuspendAnimations();
    this.radPanorama1.PanoramaElement.DragDropService = new CustomTileDragDropService(this.radPanorama1.PanoramaElement);
}
  
public class CustomTileDragDropService : TileDragDropService
{
    private RadPanoramaElement owner;
  
    public CustomTileDragDropService(RadPanoramaElement owner) : base(owner)
    {
        this.owner = owner;
    }
     
    protected override bool PrepareContext()
    {
        zoomedOutTiles = true;
        return base.PrepareContext();
    }
  
    protected override void HandleMouseMove(Point mousePos)
    {
        base.HandleMouseMove(mousePos);
        ZoomInTiles();//do not scale tiles
  
        //stop position offset of hovered tiles
        Point clientPoint = this.owner.PointFromScreen(mousePos);
        RadTileElement source = (this.Context as RadTileElement);
        if (source == null)
        {
            return ;
        }
        TileGroupElement targetGroup = this.GetTargetGroup(new RectangleF(clientPoint, source.Size));
        if (targetGroup == null)
        {
            return ;
        }
         
        Point targetCell = this.GetTargetCell(targetGroup, clientPoint);
        if (targetCell.X == -1)
        {
            return ;
        }
  
        foreach (RadTileElement tile in targetGroup.Items)
        {
            tile.PositionOffset = new SizeF(0, 0);
        }
    }
  
    protected override void PerformStop()
    {
        base.PerformStop();
        zoomedOutTiles = false;
    }
  
    bool zoomedOutTiles = false;
  
    private IEnumerable GetTiles()
    {
        if (this.owner.ShowGroups)
        {
            ArrayList tiles = new ArrayList();
            foreach (TileGroupElement group in this.owner.Groups)
            {
                foreach (RadTileElement tile in group.Items)
                {
                    tiles.Add(tile);
                }
            }
  
            return tiles;
        }
        else
        {
            return this.owner.Items.ToArray();
        }
    }
  
    private void ZoomInTiles()
    {
        if (!this.zoomedOutTiles)
        {
            return;
        }
  
        AnimatedPropertySetting offsetAnimation = new AnimatedPropertySetting(GridLayout.CellPaddingProperty,
            new Padding(10),
            new Padding(5),
            3, 25);
        offsetAnimation.RemoveAfterApply = true;
      
        foreach (RadTileElement tile in this.GetTiles())
        {
            AnimatedPropertySetting scaleAnimation = new AnimatedPropertySetting(RadElement.ScaleTransformProperty,
                tile.ScaleTransform,
                new SizeF(1, 1),
                3, 25);
            scaleAnimation.RemoveAfterApply = true;
  
            if (tile != this.Context)
            {
                scaleAnimation.ApplyValue(tile);
                offsetAnimation.ApplyValue(tile);
            }
        }
  
        this.zoomedOutTiles = false;
    }
}

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Simon
Top achievements
Rank 1
answered on 15 Dec 2015, 09:52 AM

Hi Dess,

Thanks a lot for your help. It's exactly what I'm looking for.

I have one more question. I put the component RadPanorama in a RadScrollablePanel and I would like know if it's possible to make the action of the mouse Wheel horizontally?

Regards,

Simon

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Dec 2015, 12:44 PM
Hello Simon,

Thank you for writing back.

In order to stop the default vertical scrolling when using the mouse wheel, it is appropriate to use IMessageFilter. Additional information is available on the following link: https://social.msdn.microsoft.com/Forums/windows/en-US/6bfb9287-986d-4c60-bbcc-23486e239384/making-a-scrollable-panel-scroll-with-mousewheel-just-by-hovering-mouse?forum=winforms

Following the illustrated approach, I handled the mouse wheel message and performed horizontal scrolling:
internal class ScrollPanelMessageFilter : IMessageFilter
{
    int WM_MOUSEWHEEL = 0x20A;
    Panel panel;
    bool panelHasFocus = false;
 
    [DllImport("user32.dll")]
    static extern bool GetCursorPos(ref Point lpPoint);
 
    [DllImport("User32.dll")]
    static extern Int32 SendMessage(int hWnd, int Msg, int wParam, int lParam);
 
    public ScrollPanelMessageFilter(Panel panel)
    {
        this.panel = panel;
        AddFocusEvent(panel);
    }
 
    private void AddFocusEvent(Control parentControl)
    {
        foreach (Control control in parentControl.Controls)
        {
            if (control.Controls.Count == 0)
            {
                control.GotFocus += new EventHandler(control_GotFocus);
                control.LostFocus += new EventHandler(control_LostFocus);
            }
            else
            {
                AddFocusEvent(control);
            }
        }
    }
 
    void control_GotFocus(object sender, EventArgs e)
    {
        panelHasFocus = true;
    }
 
    void control_LostFocus(object sender, EventArgs e)
    {
        panelHasFocus = false;
    }
 
    #region IMessageFilter Members
 
    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == WM_MOUSEWHEEL && panel.CanFocus && panelHasFocus && panel.VerticalScroll.Visible)
        {
            //move the horizontal scrollbar
            panel.HorizontalScroll.Value = Math.Min(panel.HorizontalScroll.Maximum,
                panel.HorizontalScroll.Value + panel.HorizontalScroll.SmallChange);
             
            return true;
        }
        return false;
    }
     
    #endregion
}
 
private ScrollPanelMessageFilter filter;
 
public Form1()
{
    InitializeComponent();
     
    this.Activated += Form1_Activated;
    this.Deactivate += Form1_Deactivate;
}
 
private void Form1_Deactivate(object sender, EventArgs e)
{
    Application.RemoveMessageFilter(filter);
}
 
private void Form1_Activated(object sender, EventArgs e)
{
    filter = new ScrollPanelMessageFilter(this.radScrollablePanel1.PanelContainer);
    Application.AddMessageFilter(filter);
}

Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Panorama
Asked by
Simon
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Simon
Top achievements
Rank 1
Share this question
or