Пример #1
0
        public VariableThumb(Canvas parentCanvas, double width = 100, double height = 100)
        {
            ParentCanvas = parentCanvas;
            this.Width   = width;
            this.Height  = height;

            //8つのマーカー■作成
            //配列の位置で配置する位置に対応
            //┏━┓ 3,4,5
            //┃  ┃ 2   6
            //┗━┛ 1,0,7
            //順番は下から時計回りで、下、左下、左、左上、上、右上、右、右下
            //Tagに目印のindex番号を入れる
            Marker8 = new FlatThumb[8];
            for (int i = 0; i < 8; i++)
            {
                var ft = new FlatThumb()
                {
                    Width = 20, Height = 20, Tag = i
                };
                ft.SetFillColor(Color.FromArgb(30, 0, 255, 255));
                Marker8[i]    = ft;
                ft.DragDelta += MarkerThumb_DragDelta;
                //ft.SetOutLine(Colors.Black, 1);//実線の枠
                //破線の枠
                ft.SetOutLine(Colors.Black, 1, new DoubleCollection(new List <double> {
                    2, 4
                }));
                ft.Cursor = Cursors.Hand;
            }

            this.DragDelta   += VariableThumb_DragDelta;
            this.SizeChanged += VariableThumb_SizeChanged;

            //AddThumbs8();
            //Thumbs8SetLocate();
        }
Пример #2
0
        //マーカーのドラッグ移動時
        //Thumbのサイズと位置を更新する
        private void MarkerThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            FlatThumb MarkerThumb = (FlatThumb)sender;
            double    w           = this.Width;
            double    h           = this.Height;
            double    l           = Canvas.GetLeft(this);
            double    t           = Canvas.GetTop(this);
            double    xMove       = e.HorizontalChange;
            double    yMove       = e.VerticalChange;

            //Thumbの横幅と横位置を計算
            void yoko()
            {
                if (w - xMove < 1) //幅1ピクセル未満になる場合
                {
                    l = l + w - 1; //幅1ピクセルの位置で固定
                    w = 1;         //幅1ピクセルを指定
                }
                else
                {
                    l += xMove;
                    w -= xMove;
                }
            }

            //縦幅と位置を計算、1ピクセル未満にならないよう修正
            void tate()
            {
                if (h - yMove < 1)
                {
                    t = t + h - 1;
                    h = 1;
                }
                else
                {
                    t += yMove;
                    h -= yMove;
                }
            }

            //Thumbの位置とサイズ変更する
            switch (MarkerThumb.Tag)
            {
            case 0:    //下
                h += yMove;
                break;

            case 1:
                yoko();
                h += yMove;
                break;

            case 2:    //左
                yoko();
                break;

            case 3:    //左上
                yoko();
                tate();
                break;

            case 4:    //上
                tate();
                break;

            case 5:
                w += xMove;
                tate();
                break;

            case 6:    //右
                w += xMove;
                break;

            case 7:
                w += xMove;
                h += yMove;
                break;

            default:
                break;
            }
            //1ピクセル未満にならないよう修正
            if (w < 0)
            {
                w = 1;
            }
            if (h < 0)
            {
                h = 1;
            }

            //Thumbのサイズと位置を指定
            this.Width  = w;
            this.Height = h;
            Canvas.SetLeft(this, l);
            Canvas.SetTop(this, t);
        }