Ejemplo n.º 1
0
        /// <summary>
        ///     技術ツリーピクチャーボックスにドロップした時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPictureBoxDragDrop(object sender, DragEventArgs e)
        {
            // ドラッグアンドドロップが無効ならば何もしない
            if (!AllowDragDrop)
            {
                return;
            }

            // ラベルでなければ何もしない
            if (!e.Data.GetDataPresent(typeof(Label)))
            {
                return;
            }

            Label label = e.Data.GetData(typeof(Label)) as Label;

            if (label == null)
            {
                return;
            }

            // 技術ツリー上のドロップ座標を計算する
            Point p = new Point(e.X, e.Y);

            p   = _pictureBox.PointToClient(p);
            p.X = label.Left + p.X - _dragPoint.X;
            p.Y = label.Top + p.Y - _dragPoint.Y;

            // ラベル情報の座標を更新する
            TechLabelInfo info = label.Tag as TechLabelInfo;

            if (info == null)
            {
                return;
            }
            info.Position.X = DeviceCaps.GetUnscaledWidth(p.X);
            info.Position.Y = DeviceCaps.GetUnscaledHeight(p.Y);

            // ラベルの座標を更新する
            label.Location = p;

            // イベントハンドラを呼び出す
            ItemDragDrop?.Invoke(this, new ItemDragEventArgs(info.Item, info.Position, e));
        }