c# winfrom 放大镜功能

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Threading;
 10
 11 namespace test
 12 {
 13     public partial class Form2 : Form
 14     {
 15         private bool blIsDrawRectangle = true;
 16         private Point ptBegin = new Point();
 17         Thread thDraw;
 18         delegate void myDrawRectangel();
 19         myDrawRectangel myDraw;
 20         public Form2()
 21         {
 22             InitializeComponent();
 23         }
 24
 25         private void pictureBox1_Paint(object sender, PaintEventArgs e)
 26         {
 27             if (blIsDrawRectangle)
 28             {
 29                 e.Graphics.DrawRectangle(new Pen(Brushes.Black, 1), ptBegin.X, ptBegin.Y, 50, 50);
 30             }
 31         }
 32
 33         private void Form2_Load(object sender, EventArgs e)
 34         {
 35             myDraw = new myDrawRectangel(ShowDrawRectangle);
 36             thDraw = new Thread(Run);
 37             thDraw.Start();
 38         }
 39         private void Run()
 40         {
 41             while (true)
 42             {
 43                 if (pictureBox1.Image != null)
 44                 {
 45                     this.BeginInvoke(myDraw);
 46                 }
 47                 Thread.Sleep(50);
 48             }
 49         }
 50         private void ShowDrawRectangle()
 51         {
 52             Rectangle rec = new Rectangle(ptBegin.X * pictureBox1.Image.Size.Width / 460,
 53                 ptBegin.Y * pictureBox1.Image.Size.Height / 350, 50 * pictureBox1.Image.Size.Width / 460,
 54                 50 * pictureBox1.Image.Size.Height / 350);
 55             Graphics g = pictureBox2.CreateGraphics();
 56             g.DrawImage(pictureBox1.Image, pictureBox2.ClientRectangle, rec, GraphicsUnit.Pixel);
 57             g.Flush();
 58         }
 59
 60         private void pictureBox1_MouseLeave(object sender, EventArgs e)
 61         {
 62             blIsDrawRectangle = false;
 63             pictureBox1.Refresh();
 64         }
 65
 66         private void pictureBox1_MouseEnter(object sender, EventArgs e)
 67         {
 68             blIsDrawRectangle = true;
 69         }
 70
 71         private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
 72         {
 73             if (e.X - 25 <= 0)
 74             {
 75                 ptBegin.X = 0;
 76             }
 77             else if (pictureBox1.Size.Width - e.X <= 25)
 78             {
 79                 ptBegin.X = pictureBox1.Size.Width - 50;
 80             }
 81             else
 82             {
 83                 ptBegin.X = e.X - 25;
 84             }
 85
 86             if (e.Y - 25 <= 0)
 87             {
 88                 ptBegin.Y = 0;
 89             }
 90             else if (pictureBox1.Size.Height-e.Y<=25)
 91             {
 92                 ptBegin.Y = pictureBox1.Size.Height - 50;
 93             }
 94             else
 95             {
 96                 ptBegin.Y = e.Y - 25;
 97             }
 98             pictureBox1.Refresh();
 99         }
100     }
101 }

时间: 2024-07-29 15:11:52

c# winfrom 放大镜功能的相关文章

javascript 实现图片放大镜功能

淘宝上经常用到的一个功能是利用图片的放大镜功能来查看商品的细节 下面我们来实现这样一个功能吧,原理很简单: 实现一个可以随鼠标移动的虚框 在另外一个块中对应显示虚框中的内容 实现思路: 虚框用css中的透明度实现filter:alpha(opacity:20); opacity:0.2; 鼠标移动到小图上面时:虚框出现,大图对应出现 细节注意的地方: 1:虚框的定位:保持鼠标位于虚框的中心,如何处理鼠标中心距离四边距离小于虚框半径(或者方形的边长的一半)的情况? 2:保持大图中显示的内容是虚框选

用JS做一个简单的电商产品放大镜功能

使用js制作一个简单的产品放大图 购物网站的产品页经常会放有一个产品展示图区.该图区有一个功能就是产品图的放大功能,移动左侧的焦点区域,可以放大细节部分观看,详情如下图.实现该功能的方法也非常简单. 实验:制作产品焦点放大图. 所需技能:1.基本的获取页面元素的方法: 2.几个简单的事件: 3.会使用dom设置元素的属性: 案例原理:1.焦点框的跟随鼠标事件: 2.焦点框的移动区域规定: 3.大盒子内容的显示: 适合对象:js初学者 -------------------------------

图片放大镜功能

HTML: <div class="pr_hLeft"> <div class="imgLeft"> <!--中号图--> <div class="Medium"> <!-- 放大镜 --> <div class="magnifier" id="magnifier"> <img src="http://product.d

放大镜功能

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title>    <style>        * {            margin: 0;            padding: 0;        } .box {            width: 350px;   

电商网站的放大镜功能

首先是样式部分,分别定义一大一小两个盒子,用来盛放大图片和小图片. <style > *{ padding: 0; margin: 0; } #demo { display: block; width: 400px; height: 255px; margin: 50px; position: relative; border: 1px solid #ccc; } #small_box { position: absolute; z-index: 1; } #mark { position:

jquey实现放大镜功能

(function ($) { $.fn.imagezoom = function (options) { var settings = { xzoom: 220, yzoom: 220, offset: 10, position: "BTR", preload: 1, scale:1 }; if (options) { $.extend(settings, options); } var noalt = '',iTop,iLeft,iWidth,iHeight; var self =

B2C电子商务系统研发——产品媒体常见功能点

产品媒体常见功能点 电商研发系列——产品媒体常见功能点 支持图片.视频和文档等媒体类型 产品图片对清晰度要求比极高,但又不能太大,所以图片一般是jpg格式. 视频一般是flv流媒体格式,如果是嵌入产品详细描述的视频,可以是优酷.youTube等视频网站的视频. 文档一般是pdf格式,用途多是帮助文档. 需要支持多张图,其中一张为主图 支持生成多种尺寸的图片 在不同的页面需要不同的尺寸,而这不能通过css直接设置高度宽度来控制,因为这样将导致整个页面太大, 降低页面访问速度,用户体验会很差.所以需

preview放大镜

[preview放大镜] preview有放大镜功能,放`键即可(键盘左上角,1左边的键). preview放大镜,布布扣,bubuko.com

利用JS实现购物网站商品放大镜效果

大家几乎都有在网上购物的经验,有的网站会有一个商品放大镜功能, 就是把鼠标移到图片上的时候,旁边会有另外一张大的图片展示,等同于 放大镜效果,那这样的效果怎样实现的呢,我把代码发给大家,请大家参考. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>放大镜</title> <style> *{m