コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: gogowaten/2021WPF
        /// <summary>
        /// ドラッグ移動中のThumbとその他のThumbとの重なり合う部分の面積を計算、
        /// 一定以上の面積があった場合、場所を入れ替えて整列
        /// </summary>
        /// <param name="t">ドラッグ移動中のThumb</param>
        /// <param name="x">Canvas上でのX座標</param>
        /// <param name="y">Canvas上でのY座標</param>
        private void Idou移動中処理(FlatThumb t, double x, double y)
        {
            t.Opacity = 0.7;
            int imaIndex = MyThumbs.IndexOf(t);//ドラッグ移動中ThumbのIndex

            MyStatus.Content = imaIndex.ToString();

            //最寄りのPoint
            int    moyoriIndex = 0;
            double moyori距離    = double.MaxValue;

            for (int i = 0; i < MyPoints.Count; i++)
            {
                double distance = GetDistance(MyPoints[i], new Point(x, y));
                if (distance < moyori距離)
                {
                    moyori距離    = distance;
                    moyoriIndex = i;
                }
            }

            //最短距離のIndexと移動中のThumbのIndexが違うなら入れ替え処理
            if (moyoriIndex != imaIndex)
            {
                //Thumbリストのindexを入れ替え
                MyThumbs.RemoveAt(imaIndex);
                MyThumbs.Insert(moyoriIndex, t);

                //indexに従って表示位置変更
                ReplaceThumb表示位置更新(moyoriIndex);
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: gogowaten/2021WPF
        //ドラッグ移動終了イベント時、
        //Indexに対応した位置に移動させる
        private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            FlatThumb t        = sender as FlatThumb;
            int       imaIndex = MyThumbs.IndexOf(t);

            //元のx座標へ移動
            Canvas.SetLeft(t, MyPoints[imaIndex].X);
            Canvas.SetTop(t, MyPoints[imaIndex].Y);

            MyStatus.Content = "";
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: gogowaten/2021WPF
        //ドラッグ移動イベント時
        private void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            //移動
            FlatThumb t = sender as FlatThumb;
            double    x = Canvas.GetLeft(t) + e.HorizontalChange;
            double    y = Canvas.GetTop(t) + e.VerticalChange;

            Canvas.SetLeft(t, x);
            Canvas.SetTop(t, y);
            t.Opacity = 0.5;

            Idou移動中処理(t, x, y);
        }