zoukankan      html  css  js  c++  java
  • [转]鼠标移到图像上显示激活的例子

    原文作者 java_liyic#+Gdi,怎么移动和改变已经绘制好的图形位置和大小

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace DrawTest
    {
        public delegate void DrawMeHandler(Graphics g);
        public delegate void MouseMoveHandler(Point p);
        public partial class Canvas : UserControl
        {
            RectangleFigure rectangleFigure = new RectangleFigure();
            DrawMeHandler drawMeHandler;
            MouseMoveHandler mouseMoveHandler;
            public Canvas()
            {
                InitializeComponent();
                this.DoubleBuffered = true;
                this.Paint += Canvas_Paint;
                this.Load += Canvas_Load;
                this.MouseMove += Canvas_MouseMove;
            }
    
            void Canvas_MouseMove(object sender, MouseEventArgs e)
            {
                this.mouseMoveHandler.Invoke(e.Location);
                this.Refresh();
            }
    
            void Canvas_Load(object sender, EventArgs e)
            {
                rectangleFigure.X = 10;
                rectangleFigure.Y = 10;
                rectangleFigure.Width = 100;
                rectangleFigure.Height = 50;
                drawMeHandler = new DrawMeHandler(rectangleFigure.DrawMe);
                mouseMoveHandler = new MouseMoveHandler(rectangleFigure.MouseMove);
                
            }
    
            void Canvas_Paint(object sender, PaintEventArgs e)
            {
                if (drawMeHandler != null) drawMeHandler.Invoke(e.Graphics);
            }
    
    
            /// <summary>
            /// 矩形对象
            /// </summary>
            public class RectangleFigure
            {
                
                public int X { get; set; }
                public int Y { get; set; }
                public int Height { get; set; }
                public int Width { get; set; }
    
                public bool Actived { get; set; }
    
                public bool IsExist(Point p)
                {
                    Rectangle rectangle = new Rectangle(this.X, this.Y, this.Width, this.Height);
                    return rectangle.Contains(p);
                }
    
                public void MouseMove(Point p)
                {
                    Actived = IsExist(p);
                }
    
                public void DrawMe(Graphics g)
                {
                    Pen p = new Pen(Color.Black);
                    g.FillRectangle(p.Brush, this.X, this.Y, this.Width, this.Height);
                    if (Actived)
                    {
                        p.Color = Color.Red;
                        g.DrawRectangle(p, this.X, this.Y, this.Width, this.Height);
                    }
                }
            }
        }
    }
    
  • 相关阅读:
    触发器
    新登录用户的次日成功的留存率
    获取薪水第二多的
    找到薪水比经理高的员工
    成绩排名
    exists 和 in
    sum+case 计数
    前N个员工的salary累计和
    员工的薪水按照salary进行按照1N的排名,相同salary并列
    洛谷2678 跳石头
  • 原文地址:https://www.cnblogs.com/arxive/p/5810773.html
Copyright © 2011-2022 走看看