Пример #1
0
        /// <summary>
        /// Handles the Key Down situation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            // Allow panning if the space is pressed.
            if (e.KeyCode == Keys.Space && !isPanningTemporarily)
            {
                previousFunction     = Map.FunctionMode;
                Map.FunctionMode     = FunctionMode.Pan;
                isPanningTemporarily = true;
            }

            // Arrow-Key Panning
            if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
            {
                if (!BusySet)
                {
                    Map.IsBusy = true;
                    BusySet    = true;
                }

                var _source = Map.MapFrame.View;

                switch (e.KeyCode)
                {
                case Keys.Up:
                    Map.MapFrame.View = new Rectangle(_source.X, _source.Y - 20, _source.Width, _source.Height);
                    break;

                case Keys.Down:
                    Map.MapFrame.View = new Rectangle(_source.X, _source.Y + 20, _source.Width, _source.Height);
                    break;

                case Keys.Left:
                    Map.MapFrame.View = new Rectangle(_source.X - 20, _source.Y, _source.Width, _source.Height);
                    break;

                case Keys.Right:
                    Map.MapFrame.View = new Rectangle(_source.X + 20, _source.Y, _source.Width, _source.Height);
                    break;
                }

                KeyPanCount++;

                if (KeyPanCount == 16)
                {
                    Map.MapFrame.ResetExtents();
                    KeyPanCount = 0;
                }
                else
                {
                    Map.Invalidate();
                }
            }

            // Zoom Out
            if (e.KeyCode == (Keys.LButton | Keys.MButton | Keys.Back | Keys.ShiftKey | Keys.Space | Keys.F17) || e.KeyCode == Keys.Subtract)
            {
                Extent MaxExtent = Map.GetMaxExtent();
                if ((Map.IsZoomedToMaxExtent == true))
                {
                }
                else
                {
                    Map.IsBusy = true;
                    Rectangle r = Map.MapFrame.View;

                    r.Inflate(r.Width / 2, r.Height / 2);
                    Map.MapFrame.View = r;
                    Map.MapFrame.ResetExtents();
                    Map.IsBusy = false;
                }
            }

            // Zoom In
            if (e.KeyCode == (Keys.LButton | Keys.RButton | Keys.Back | Keys.ShiftKey | Keys.Space | Keys.F17) || e.KeyCode == Keys.Add)
            {
                Map.IsBusy = true;
                Map.IsZoomedToMaxExtent = false;
                Rectangle r = Map.MapFrame.View;

                r.Inflate(-r.Width / 4, -r.Height / 4);

                Map.MapFrame.View = r;
                Map.MapFrame.ResetExtents();
                Map.IsBusy = false;
            }
        }