当前位置: 首页>>代码示例>>C#>>正文


C# MouseEventArgs.Position方法代码示例

本文整理汇总了C#中System.Windows.Forms.MouseEventArgs.Position方法的典型用法代码示例。如果您正苦于以下问题:C# MouseEventArgs.Position方法的具体用法?C# MouseEventArgs.Position怎么用?C# MouseEventArgs.Position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.MouseEventArgs的用法示例。


在下文中一共展示了MouseEventArgs.Position方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MapContainer_MouseUp

        /// <summary>
        /// Handles when the mouse button is raised on a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                     MouseEventArgs e)
        {
            var cursorPos = e.Position();
            var worldPos = camera.ToWorld(cursorPos);

            // Create entity
            if (e.Button == MouseButtons.Right)
            {
                Type createType = null;

                // Create using same type as the last entity, if possible
                if (Input.IsCtrlDown)
                    createType = _lastCreatedType;

                // Display selection dialog
                if (createType == null)
                {
                    using (var frm = new EntityTypeUITypeEditorForm(_lastCreatedType))
                    {
                        if (frm.ShowDialog(sender as IWin32Window) == DialogResult.OK)
                            createType = frm.SelectedItem;
                    }
                }

                // Create the type
                if (createType != null)
                {
                    _lastCreatedType = null;

                    try
                    {
                        // Create the Entity
                        var entity = (Entity)Activator.CreateInstance(createType);
                        map.AddEntity(entity);
                        entity.Size = new Vector2(64);
                        entity.Position = worldPos - (entity.Size / 2f);

                        GridAligner.Instance.Fit(entity);

                        _lastCreatedType = createType;
                    }
                    catch (Exception ex)
                    {
                        const string errmsg = "Failed to create entity of type `{0}` on map `{1}`. Exception: {2}";
                        if (log.IsErrorEnabled)
                            log.ErrorFormat(errmsg, createType, map, ex);
                        Debug.Fail(string.Format(errmsg, createType, map, ex));
                    }
                }
            }

            base.MapContainer_MouseUp(sender, map, camera, e);
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:61,代码来源:MapEntityCursorTool.cs

示例2: MapContainer_MouseDown

        /// <summary>
        /// Handles when a mouse button is pressed on a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                       MouseEventArgs e)
        {
            base.MapContainer_MouseDown(sender, map, camera, e);

            if (IsSelecting)
                return;

            // Left-click
            if (e.Button == MouseButtons.Left)
            {
                // Place light
                if (Input.IsKeyDown(_placeLightKey))
                {
                    var msc = MapScreenControl.TryFindInstance(map);
                    if (msc != null)
                    {
                        var dm = msc.DrawingManager;
                        if (dm != null)
                        {
                            var pos = camera.ToWorld(e.Position());
                            pos = GridAligner.Instance.Align(pos);

                            var light = new Light { Center = pos, IsEnabled = true, Tag = map };

                            map.AddLight(light);
                            dm.LightManager.Add(light);
                        }
                    }
                }
            }
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:39,代码来源:MapLightCursorTool.cs

示例3: MapContainer_MouseMove

        /// <summary>
        /// Handles when the mouse moves over a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                       MouseEventArgs e)
        {
            base.MapContainer_MouseMove(sender, map, camera, e);

            var cursorPos = e.Position();

            _mouseOverMap = map;
            _mousePos = cursorPos;
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:17,代码来源:MapLightCursorTool.cs

示例4: MapContainer_MouseDown

        /// <summary>
        /// Handles when a mouse button is pressed on a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                       MouseEventArgs e)
        {
            var wasMapGrhPlaced = false;

            if (e.Button == MouseButtons.Left)
            {
                // Left-click
                if (Input.IsKeyDown(_placeMapGrhKey))
                {
                    PlaceMapGrh(map, camera, e.Position(), TileMode);
                    wasMapGrhPlaced = true;
                }
            }

            base.MapContainer_MouseDown(sender, map, camera, e);

            if (wasMapGrhPlaced)
                SOM.Clear();
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:27,代码来源:MapGrhCursorTool.cs

示例5: MapContainer_MouseMove

        /// <summary>
        /// Handles when the mouse moves over a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                       MouseEventArgs e)
        {
            base.MapContainer_MouseMove(sender, map, camera, e);

            var cursorPos = e.Position();

            _mouseOverMap = map;
            _mousePos = cursorPos;

            // Support dragging operations when using TileMode
            if (TileMode)
            {
                if (Input.IsKeyDown(_placeMapGrhKey))
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        // Drag placement
                        PlaceMapGrh(map, camera, e.Position(), true);
                    }
                    else if (e.Button == MouseButtons.Right)
                    {
                        // Drag delete
                        var worldPos = camera.ToWorld(e.Position());
                        worldPos = GridAligner.Instance.Align(worldPos, true);
                        var worldPosArea = worldPos.ToRectangle(Vector2.One, false);
                        var toDelete = map.Spatial.GetMany<MapGrh>(worldPosArea, x => IsObjectVisible(map, x));

                        foreach (var x in toDelete)
                        {
                            map.RemoveMapGrh(x);
                        }
                    }
                }
            }
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:43,代码来源:MapGrhCursorTool.cs

示例6: HandleMouseClickAndMove

        /// <summary>
        /// Handles both mouse clicks and moves.
        /// </summary>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        void HandleMouseClickAndMove(EditorMap map, ICamera2D camera, MouseEventArgs e)
        {
            // Update some vars
            var cursorPos = e.Position();
            _mouseOverMap = map;
            _mousePos = cursorPos;

            var globalState = GlobalState.Instance;
            var currentGrhData = globalState.Map.GrhToPlace.GrhData;

            Vector2 worldPos = camera.ToWorld(cursorPos);

            // Handle mouse
            if (e.Button == MouseButtons.Left)
            {
                if (!Input.IsShiftDown)
                {
                    // Fill
                    if (currentGrhData != null)
                    {
                        var mapGrhsToReplace = GetFillMapGrhs(map, worldPos);
                        foreach (var mapGrh in mapGrhsToReplace)
                        {
                            mapGrh.Grh.SetGrh(currentGrhData);
                        }
                    }
                }
                else
                {
                    // Select grh under cursor
                    var grhToSelect = MapGrhPencilTool.GetGrhToSelect(map, worldPos);
                    if (grhToSelect != null)
                    {
                        globalState.Map.SetGrhToPlace(grhToSelect.Grh.GrhData.GrhIndex);
                        globalState.Map.Layer = grhToSelect.MapRenderLayer;
                        globalState.Map.LayerDepth = grhToSelect.LayerDepth;
                    }
                }

            }
            else if (e.Button == MouseButtons.Right)
            {
                // Fill-delete
                if (currentGrhData != null)
                {
                    var mapGrhsToReplace = GetFillMapGrhs(map, worldPos);
                    foreach (var mapGrh in mapGrhsToReplace)
                    {
                        map.RemoveMapGrh(mapGrh);
                    }
                }
            }
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:59,代码来源:MapGrhFillTool.cs

示例7: gameScreen_MouseMove

        /// <summary>
        /// Handles the MouseMove event of the gameScreen control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        void gameScreen_MouseMove(object sender, MouseEventArgs e)
        {
            if (DesignMode)
                return;

            if ((e.Button & MouseButtons.Left) == 0)
                return;

            var emitter = lstEmitters.SelectedItem as ParticleEmitter;
            if (emitter == null)
                return;

            var camera = gameScreen.Camera;
            if (camera == null)
                return;

            emitter.Origin = camera.ToWorld(e.Position());

            if (!lstEmitters.Items.Contains(emitter))
                lstEmitters.Items.Add(emitter);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:26,代码来源:ParticleEditorForm.cs

示例8: HandleMouseMove

        /// <summary>
        /// Handles when the mouse moves.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseMove(MouseEventArgs e, ICamera2D camera)
        {
            if (_transBoxes.Count == 0)
                return false;

            var worldPos = camera.ToWorld(e.Position());
            _lastWorldPos = worldPos;

            // Update what transbox is under the cursor
            if (SelectedTransBox != null)
                UnderCursor = SelectedTransBox;
            else
                UnderCursor = FindBoxAt(worldPos);

            // Update position
            if (SelectedTransBox != null)
                SelectedTransBox.CursorMoved(_lastWorldPos);

            return SelectedTransBox != null;
        }
开发者ID:wtfcolt,项目名称:game,代码行数:26,代码来源:TransBoxManager.cs

示例9: OnMouseMove

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseMove"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (DesignMode)
            {
                base.OnMouseMove(e);
                return;
            }

            var screenPos = e.Position();
            var worldPos = Camera.ToWorld(screenPos);
            MainForm.UpdateCursorPos(worldPos, screenPos);

            if (TransBoxManager.HandleMouseMove(e, Camera))
                return;

            base.OnMouseMove(e);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:21,代码来源:MapScreenControl.cs

示例10: MapContainer_MouseUp

        /// <summary>
        /// Handles when the mouse button is raised on a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                     MouseEventArgs e)
        {
            if (IsSelecting && e.Button == SelectMouseButton)
            {
                // End the mass selection

                _selectionEnd = camera.ToWorld(e.Position());

                var area = Rectangle.FromPoints(_selectionStart, _selectionEnd);

                var selected = CursorSelectObjects(map, area);
                GlobalState.Instance.Map.SelectedObjsManager.SetManySelected(selected);

                _isSelecting = false;
                _selectionStart = Vector2.Zero;
                _selectionEnd = Vector2.Zero;
            }

            base.MapContainer_MouseUp(sender, map, camera, e);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:28,代码来源:MapCursorToolBase.cs

示例11: HandleMouseDown

        /// <summary>
        /// Handles when a mouse button is pressed down.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseDown(MouseEventArgs e, ICamera2D camera)
        {
            if (e.Button == DragButton)
            {
                var worldPos = camera.ToWorld(e.Position());

                UnderCursor = FindBoxAt(worldPos);
                SelectedTransBox = UnderCursor;
                _lastWorldPos = worldPos;

                if (SelectedTransBox != null)
                    _selectedTransBoxButton = e.Button;
                else
                    _selectedTransBoxButton = MouseButtons.None;
            }

            return SelectedTransBox != null;
        }
开发者ID:wtfcolt,项目名称:game,代码行数:24,代码来源:TransBoxManager.cs

示例12: MapContainer_MouseMove

        /// <summary>
        /// Handles when the mouse moves over a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                       MouseEventArgs e)
        {
            _mouseOverMap = map;

            var worldPos = camera.ToWorld(e.Position());

            if (IsSelecting)
            {
                // Expand selection area
                _selectionEnd = worldPos;
            }
            else
            {
                // Create the tooltip
                var font = ToolTipFont;
                if (ShowObjectToolTip && font != null)
                {
                    var hoverEntity = GetObjUnderCursor(map, worldPos);

                    if (hoverEntity == null)
                    {
                        // Nothing under the cursor that we are allowed to select
                        _toolTip = string.Empty;
                        _toolTipObject = null;
                    }
                    else if (_toolTipObject != hoverEntity)
                    {
                        // Something found under the cursor
                        _toolTipObject = hoverEntity;
                        _toolTipPos = e.Position();
                        _toolTip = GetObjectToolTip(hoverEntity) ?? hoverEntity.ToString();

                        // Make sure the text stays in the view area
                        const int toolTipPadding = 4;
                        var toolTipSize = font.MeasureString(_toolTip);

                        if (_toolTipPos.X < toolTipPadding)
                            _toolTipPos.X = toolTipPadding;
                        else if (_toolTipPos.X + toolTipSize.X + toolTipPadding > camera.Size.X)
                            _toolTipPos.X = camera.Size.X - toolTipSize.X - toolTipPadding;

                        if (_toolTipPos.Y < toolTipPadding)
                            _toolTipPos.Y = toolTipPadding;
                        else if (_toolTipPos.Y + toolTipSize.Y + toolTipPadding > camera.Size.Y)
                            _toolTipPos.Y = camera.Size.Y - toolTipSize.Y - toolTipPadding;
                    }
                }
            }

            base.MapContainer_MouseMove(sender, map, camera, e);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:59,代码来源:MapCursorToolBase.cs

示例13: MapContainer_MouseDown

        /// <summary>
        /// Handles when a mouse button is pressed on a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
                                                       MouseEventArgs e)
        {
            // Terminate any current area selection when any mouse button is pressed
            _selectionStart = Vector2.Zero;
            _selectionEnd = Vector2.Zero;
            _isSelecting = false;

            var worldPos = camera.ToWorld(e.Position());
            var underCursor = GetObjUnderCursor(map, worldPos);

            GlobalState.Instance.Map.SelectedObjsManager.SetSelected(underCursor);

            if (e.Button == SelectMouseButton && ((Control.ModifierKeys & SelectKey) != 0))
            {
                // Start area selection
                _selectionStart = worldPos;
                _selectionEnd = _selectionStart;
                _isSelecting = true;
            }

            base.MapContainer_MouseDown(sender, map, camera, e);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:30,代码来源:MapCursorToolBase.cs

示例14: HandleMouseClickAndMove

        /// <summary>
        /// Handles both mouse clicks and moves (does the place/deletes of grhs).
        /// </summary>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        void HandleMouseClickAndMove(EditorMap map, ICamera2D camera, MouseEventArgs e)
        {
            // Update some vars
            var cursorPos = e.Position();
            _mouseOverMap = map;
            _mousePos = cursorPos;

            // Don't do any place/deletes while selecting
            if (IsSelecting)
                return;

            Vector2 worldPos = camera.ToWorld(cursorPos);

            // Handle mouse
            if (e.Button == MouseButtons.Left)
            {
                if (!Input.IsShiftDown)
                {
                    // Place grh
                    PlaceMapGrhAtScreenPos(map, camera, cursorPos, !Input.IsCtrlDown);
                }
                else
                {
                    // Select grh under cursor
                    var grhToSelect = GetGrhToSelect(map, worldPos);
                    if (grhToSelect != null)
                    {
                        GlobalState.Instance.Map.SetGrhToPlace(grhToSelect.Grh.GrhData.GrhIndex);
                        GlobalState.Instance.Map.Layer = grhToSelect.MapRenderLayer;
                        GlobalState.Instance.Map.LayerDepth = grhToSelect.LayerDepth;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (!Input.IsShiftDown)
                {
                    // Delete from current layer
                    var grhToDelete = GetGrhToSelect(map, worldPos, mustBeOnLayer: GlobalState.Instance.Map.Layer);
                    if (grhToDelete != null)
                        map.RemoveMapGrh(grhToDelete);
                }
                else
                {
                    // Delete from all layers
                    var grhToSelect = GetGrhToSelect(map, worldPos);
                    if (grhToSelect != null)
                        map.RemoveMapGrh(grhToSelect);
                }
            }
        }
开发者ID:wtfcolt,项目名称:game,代码行数:57,代码来源:MapGrhPencilTool.cs

示例15: MapContainer_MouseDown

        /// <summary>
        /// Handles when the mouse button is raised on a map.
        /// </summary>
        /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
        /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
        protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e)
        {
            var cursorPos = e.Position();
            var worldPos = camera.ToWorld(cursorPos);

            if (e.Button == MouseButtons.Right)
            {
                var ga = GridAligner.Instance;

                var entity = new WallEntity(worldPos, ga.GridSize);

                ga.Fit(entity);

                map.AddEntity(entity);
                SOM.SetSelected(entity);
            }

            base.MapContainer_MouseDown(sender, map, camera, e);
        }
开发者ID:wtfcolt,项目名称:game,代码行数:26,代码来源:MapWallCursorTool.cs


注:本文中的System.Windows.Forms.MouseEventArgs.Position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。