资源简介
C#写的放大镜程序,模拟真实放大镜的效果,能放大鼠标位置的区域并直接显示在鼠标的位置,不偏移显示,效果跟真实放大镜一样,鼠标滚轮可调节放大倍率,ESC键退出.只是代码雏形,没有完全完成,卡在实时更新的问题,希望网友们集思广益,一起实现.

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const float zommDelta = 0.2f;
private float zoom = 2;
private float lastZoom = 2;
private Point offset = new Point(0 0);
private Point lastMousePosition = new Point(0 0);
private Bitmap tempMap;
public Form1()
{
InitializeComponent();
Setstyle(Controlstyles.UserPaint true);
Setstyle(Controlstyles.DoubleBuffer true);
Setstyle(Controlstyles.AllPaintingInWmPaint true);
Setstyle(Controlstyles.ResizeRedraw true);
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseWheel);
}
private void Form1_PreviewKeyDown(object sender PreviewKeyDownEventArgs e)
{
if (e.KeyValue == 27)
{
Close();
}
}
private void Form1_MouseWheel(object sender System.Windows.Forms.MouseEventArgs e)
{
if (e.Delta > 0)
{
zoom += zommDelta;
}
else
{
zoom -= zommDelta;
if (zoom < 1) zoom = 1;
}
DoMove();
}
private void timer1_Tick(object sender EventArgs e)
{
DoMove();
}
private void DoMove()
{
Point newMousePosition = MousePosition;
if (lastMousePosition != newMousePosition || lastZoom != zoom)
{
lastZoom = zoom;
offset = lastMousePosition - new Size(newMousePosition);
lastMousePosition = newMousePosition;
Point mousePosition = MousePosition;
mousePosition.Offset(-Width / 2 -Height / 2);
Bitmap newMap = GetScreen(new Rectangle(mousePosition Size));
if (tempMap != null)
{
Graphics g = Graphics.FromImage(newMap);
g.DrawImage(tempMap offset);
}
tempMap = newMap;
Location = mousePosition;
Invalidate();
}
}
private void Form1_Shown(object sender EventArgs e)
{
DoMove();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(tempMap -Width * (zoom - 1) / 2 -Height * (zoom - 1) / 2 Width * zoom Height * zoom);
}
[DllImportAttribute(“gdi32.dll“)]
public static extern bool BitBlt(
IntPtr hdcDest
int nXDest
int nYDest
int nWidth
int nHeight
IntPtr hdcSrc
int nXSrc
int nYSrc
System.Int32 dwRop
);
private Bitmap GetScreen(Rectangle rect)
{
Graphics grpScreen = Graphics.FromHwnd(IntPtr.Zero);
Bitmap bitmap = new Bitmap(rect.Width rect.Height grpScreen);
Graphics grpBitmap = Graphics.FromImage(bitmap);
IntPtr hdcScreen = grpScreen.GetHdc();
IntPtr hdcBitmap = grpBitmap.GetHdc();
BitBlt(hdcBitmap 0 0 bitmap.Width bitmap.Height hdcScreen rect.X rect.Y 0x00CC0020);
grpBitmap.ReleaseHdc(hdcBitmap);
grpScreen.ReleaseHdc(hdcScreen);
grpBitmap.Dispose();
grpScreen.Dispose();
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10240 2013-06-07 13:39 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
文件 28160 2013-06-07 13:39 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
文件 11608 2013-06-07 13:40 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
文件 490 2010-03-17 22:39 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
文件 3035 2013-06-07 13:40 WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
文件 1817 2013-06-06 17:56 WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
文件 6011 2013-06-06 17:56 WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
文件 5513 2013-06-07 13:39 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 516 2013-06-06 17:56 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource-ResGen.read.1.tlog
文件 1198 2013-06-06 17:56 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource-ResGen.write.1.tlog
文件 1416 2013-06-07 13:40 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
文件 10240 2013-06-07 13:39 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
文件 180 2013-06-06 17:56 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
文件 28160 2013-06-07 13:39 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
文件 180 2013-06-06 14:56 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
文件 418 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
文件 1460 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
文件 2528 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
文件 5612 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
文件 1031 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
文件 249 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
文件 3455 2013-06-06 14:56 WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
文件 914 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1.sln
..A..H. 17920 2013-06-07 13:40 WindowsFormsApplication1\WindowsFormsApplication1.suo
目录 0 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\TempPE
目录 0 2013-06-07 13:39 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug
目录 0 2013-06-06 14:56 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug
目录 0 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86
目录 0 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\bin
目录 0 2013-06-06 14:50 WindowsFormsApplication1\WindowsFormsApplication1\obj
............此处省略6个文件信息
- 上一篇:c#实现D8单流向算法
- 下一篇:自动从NTP服务器同步本地时间WinForm
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论