当前位置: 首页 > wzjs >正文

axure 做网站原型优化设计三年级上册答案语文

axure 做网站原型,优化设计三年级上册答案语文,用html做静态网站,wap网站如何制作1. 控件概述 这是一个继承自 Control 的自定义控件,主要用于图像的显示和交互操作,具有以下核心功能: 图像显示与缩放(支持鼠标滚轮缩放)图像平移(支持鼠标拖拽)视图重置(双击重置…

1. 控件概述

这是一个继承自 Control 的自定义控件,主要用于图像的显示和交互操作,具有以下核心功能:

  • 图像显示与缩放(支持鼠标滚轮缩放)
  • 图像平移(支持鼠标拖拽)
  • 视图重置(双击重置)
  • 网格背景显示

2. 核心功能实现分析

2.1 图像渲染与缩放
  • 使用 InterpolationMode.HighQualityBicubic 和 PixelOffsetMode.HighQuality 实现高质量图像渲染
  • 通过 _zoom 变量控制缩放比例,_imagePosition 控制图像位置
  • 坐标转换函数 ScreenToImage 用于将屏幕坐标映射到图像坐标
private PointF ScreenToImage(Point screenPoint)
{return new PointF((screenPoint.X - _imagePosition.X) / _zoom, (screenPoint.Y - _imagePosition.Y) / _zoom);
}
2.2 视图控制
  • ResetView() 方法自动计算适合控件大小的缩放比例
  • CenterImage() 方法确保图像居中显示
  • 实现鼠标事件处理:
    • 左键拖拽实现图像平移
    • 滚轮实现缩放(缩放时保持鼠标位置不变)
    • 双击重置视图
protected override void OnMouseWheel(MouseEventArgs e)
{// 缩放前记录鼠标在图像中的位置PointF mouseInImageSpace = ScreenToImage(e.Location);// 调整缩放比例_zoom += (e.Delta > 0 ? ZoomStep : -ZoomStep);_zoom = Math.Max(MinZoom, Math.Min(MaxZoom, _zoom));// 计算缩放后的位置并调整图像位置,确保鼠标点在图像中的相对位置不变PointF mouseInScreenSpaceAfterZoom = new PointF(mouseInImageSpace.X * _zoom + _imagePosition.X,mouseInImageSpace.Y * _zoom + _imagePosition.Y);_imagePosition.X += e.Location.X - mouseInScreenSpaceAfterZoom.X;_imagePosition.Y += e.Location.Y - mouseInScreenSpaceAfterZoom.Y;Invalidate();
}
2.3 网格背景实现
  • 通过 ShowGrid 属性控制网格显示
  • 在 OnPaint 方法中绘制网格背景
  • 网格参数可配置(颜色、大小)
// 绘制网格背景
if (_showGrid)
{using (Pen gridPen = new Pen(_gridColor)){// 水平线for (float y = 0; y < Height; y += GridSize){e.Graphics.DrawLine(gridPen, 0, y, Width, y);}// 垂直线for (float x = 0; x < Width; x += GridSize){e.Graphics.DrawLine(gridPen, x, 0, x, Height);}}
}

3. 使用示例 

// 在窗体中使用自定义控件
public partial class MainForm : Form
{private CustomControl1 imageControl;public MainForm(){InitializeComponent();// 创建自定义控件实例imageControl = new CustomControl1();imageControl.Dock = DockStyle.Fill;this.Controls.Add(imageControl);// 加载图像try{imageControl.Image = Image.FromFile("example.jpg");}catch (Exception ex){MessageBox.Show($"加载图像失败: {ex.Message}");}}
}

完整代码:

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;namespace ImageControl
{public partial class CustomControl1 : Control{private Image _image;private Point _lastMousePosition;private PointF _imagePosition = new PointF(0, 0);private float _zoom = 1.0f;private const float MinZoom = 0.2f;private const float MaxZoom = 5.0f;private const float ZoomStep = 0.1f;private bool _showGrid = true;  // 新增:控制网格显示private readonly Color _gridColor = Color.LightGray;  // 新增:网格颜色private const int GridSize = 20;  // 新增:网格大小public Image Image{get => _image;set{if (_image != null && _image != value){_image.Dispose();}_image = value;// 自动调整初始缩放比例if (_image != null && this.Width > 0 && this.Height > 0){float widthRatio = (float)this.Width / _image.Width;float heightRatio = (float)this.Height / _image.Height;_zoom = Math.Min(widthRatio, heightRatio) * 0.95f;_zoom = Math.Max(MinZoom, Math.Min(MaxZoom, _zoom));}CenterImage();Invalidate();}}// 新增:网格显示属性public bool ShowGrid{get => _showGrid;set{if (_showGrid != value){_showGrid = value;Invalidate();}}}public CustomControl1(){this.DoubleBuffered = true;this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);}private PointF ScreenToImage(Point screenPoint){return new PointF((screenPoint.X - _imagePosition.X) / _zoom, (screenPoint.Y - _imagePosition.Y) / _zoom);}private RectangleF GetDestinationRectangle(){if (_image == null) return RectangleF.Empty;return new RectangleF(_imagePosition.X, _imagePosition.Y, (_image.Width * _zoom), (_image.Height * _zoom));}private void CenterImage(){if (_image == null) return;_imagePosition = new PointF((this.Width - _image.Width * _zoom) / 2,(this.Height - _image.Height * _zoom) / 2);Invalidate();}public void ResetView(){if (_image == null){_zoom = 1.0f;}else{// 计算适合控件大小的缩放比例float widthRatio = (float)this.Width / _image.Width;float heightRatio = (float)this.Height / _image.Height;_zoom = Math.Min(widthRatio, heightRatio) * 0.95f;_zoom = Math.Max(MinZoom, Math.Min(MaxZoom, _zoom));}CenterImage();}protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);// 新增:绘制网格背景if (_showGrid){using (Pen gridPen = new Pen(_gridColor)){// 水平线for (float y = 0; y < Height; y += GridSize){e.Graphics.DrawLine(gridPen, 0, y, Width, y);}// 垂直线for (float x = 0; x < Width; x += GridSize){e.Graphics.DrawLine(gridPen, x, 0, x, Height);}}}if (_image == null) return;e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;RectangleF destRect = GetDestinationRectangle();e.Graphics.DrawImage(_image, destRect);}protected override void OnResize(EventArgs e){base.OnResize(e);CenterImage();}protected override void OnDoubleClick(EventArgs e){base.OnDoubleClick(e);ResetView();}protected override void OnMouseDown(MouseEventArgs e){base.OnMouseDown(e);if (e.Button == MouseButtons.Left && _image != null){_lastMousePosition = e.Location;this.Cursor = Cursors.Hand;}}protected override void OnMouseUp(MouseEventArgs e){base.OnMouseUp(e);this.Cursor = Cursors.Default;}protected override void OnMouseMove(MouseEventArgs e){base.OnMouseMove(e);if (e.Button == MouseButtons.Left && _image != null){_imagePosition.X += (e.X - _lastMousePosition.X);_imagePosition.Y += (e.Y - _lastMousePosition.Y);_lastMousePosition = e.Location;Invalidate();}}protected override void OnMouseWheel(MouseEventArgs e){base.OnMouseWheel(e);if (_image == null) return;PointF mouseInImageSpace = ScreenToImage(e.Location);float oldZoom = _zoom;_zoom += (e.Delta > 0 ? ZoomStep : -ZoomStep);_zoom = Math.Max(MinZoom, Math.Min(MaxZoom, _zoom));PointF mouseInScreenSpaceAfterZoom = new PointF(mouseInImageSpace.X * _zoom + _imagePosition.X,mouseInImageSpace.Y * _zoom + _imagePosition.Y);_imagePosition.X += e.Location.X - mouseInScreenSpaceAfterZoom.X;_imagePosition.Y += e.Location.Y - mouseInScreenSpaceAfterZoom.Y;Invalidate();}}}

http://www.dtcms.com/wzjs/250373.html

相关文章:

  • 做网站买空间举三个成功的新媒体营销案例
  • 建设一个网站需要的条件怎么做小说推广挣钱
  • 个人网站做微擎流量精灵官网
  • 免费建一个网页的链接廊坊seo
  • 国内 上市网站建设公司html网页制作步骤
  • 互联网营销外包公司百度首页排名优化公司
  • 衡阳电商网站建设百度seo排名培训优化
  • 电商网站建设策划书搜索软件使用排名
  • h5自助建站系统百度新闻排行榜
  • 晚上睡不着看b站正常吗保定网站建设方案优化
  • 做现货值得关注的财经网站山西优化公司
  • seo网站查询属于免费的网络营销方式
  • 门户网站建设情况调研报告百度官网网站登录
  • 58同城石家庄网站建设酒店如何进行网络营销
  • 北京建设注册中心网站首页在百度怎么发布作品
  • 网上课程网站官网百度
  • 宣讲家网站支部建设免费发seo外链平台
  • wordpress中文企业主题 下载地址短视频seo搜索优化
  • 杭州 定制网站搜索引擎营销优化策略有哪些
  • 昆明网站建设哪家好竞价托管就选微竞价
  • linux 建立网站湖北seo关键词排名优化软件
  • 酒泉手机网站建设网络营销的基本方法
  • 织梦5.5模版安装上去为什么打开网站图片不能显示教程网络营销课程ppt
  • 开发网站 需求优秀网站网页设计分析
  • 做的网站怎么发布厦门seo结算
  • 沈阳市做网站的公司阿里指数官方网站
  • 商城网站页面设计高端网站建设定制
  • 武汉网页设计培训机构哪里有芜湖seo
  • 36 氪 网站如何优化旺道优化软件
  • 微网站怎么做seo推广一年要多少钱