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);
                    }
                }
            }
        }
    }
    
  • 相关阅读:
    Azure SQL Database (1) 用户手册
    Windows Azure Web Site (17) Azure Web Site 固定公网IP地址
    MongoDB数据文件内部结构
    压缩 MongoDB 的数据文件
    服务器如何选择网络带宽(转)
    刀片服务器和磁盘阵列卡(RAID)技术---永和维护(转)
    Solr打分出错
    Solr添加SolrDocument报错
    解决Windows Git Bash中文乱码问题
    HAProxy的独门武器:ebtree
  • 原文地址:https://www.cnblogs.com/arxive/p/5810773.html
Copyright © 2011-2022 走看看