Share:

RightEffect.cs | Drag Object To Scroll In WPF C# | Amit Padhiyar | Saatody

RightEffect.cs

Drag object using MouseLeftButtonDown, MouseLeftButtonUp and MouseMove. When we drag object using mouse and if object's any part is going outside parent panel then the parent panel margin automatically update and try to in that object.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Input;

namespace EffectFeatures
{
    public class RightEffect : Border
    {
        public void Initialize()
        {
            try
            {
                Repaint();
                Resize();
                Event();
                Refresh();
            }
            catch (Exception e) { }
        }
        public void Repaint()
        {
            try
            {
                this.Background = new SolidColorBrush(Color.FromArgb(100, 255, 165, 0));
                this.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 165, 0));
                this.BorderThickness = new Thickness(2);
                this.CornerRadius = new CornerRadius(5, 5, 5, 5);
            }
            catch (Exception e) { }
        }
        public void Resize()
        {
            try
            {
                this.HorizontalAlignment = HorizontalAlignment.Left;
                this.VerticalAlignment = VerticalAlignment.Top;
                this.Margin = new Thickness(9700, 0, 0, 0);
                this.Width = 300;
                this.Height = 70;
            }
            catch (Exception e) { }
        }

        public string EventCommand = "";
        private double OffsetX = 0.0;
        public void Event()
        {
            try
            {
                this.MouseLeftButtonDown += (sender, e) => {
                    OffsetX = e.GetPosition(this).X;
                    EventCommand = "Down";
                };
                MainWindow.UI.MouseLeftButtonUp += (sender, e) => {
                    EventCommand = "";
                };
                MainWindow.UI.MouseMove += (sender, e) =>
                {
                    if (Mouse.LeftButton == MouseButtonState.Pressed)
                    {
                        if(EventCommand == "Down")
                        {
                            double X = e.GetPosition(RightEffectRow.UI).X;
                            X = X - OffsetX;
                            this.Margin = new Thickness(X, 0, 0, 0);
                        }
                    }
                };
            }
            catch (Exception e) { }
        }
        public void Refresh()
        {
            try
            {

            }
            catch (Exception e) { }
        }
    }
}

Comments

Popular posts from this blog

Get Color From Pixel C# WPF | Saatody | Amit Padhiyar

Basic Audio Operations With MP3 And Wave Files Using NAudio C#

Create Drag And Drop Operation Between DevExpress GridControl And Custom WPF UI | Saatody | Amit Padhiyar