资源简介
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#实现D8单流向算法
- RunJoyStickOnLocalMachine.zip
- 基于asp.net c#在线答题页面
- HTTPS证书创建+绑定端口+C#程序监听
- 实现UDP可靠文件传输
- VB.NET C# 截屏小工具
- C# GDI+ Demo.zip
- C#写的控制台NTP服务端以及winform的N
- C# 备份还原sqlserver,SQL server还原,附
- C#的串口助手源码例程
- 立体像对的空间前方交会-点投影系数
- C#交会法测量程序.zip
- 住院收费管理系统,。数据库课程设
- 基于C# Winform完成串口通讯上位机
- 基于C#的点名小软件
- 两个DataGridView通过委托实时传值,安
- 一套类moba的教学视频百度云地址
- C#实现房屋出租管理系统
- C#支持中英文软键盘
- C#工业控制——机械手项目.rar
- 点名神器.zip
- c#操作CAD实时打开关闭
- HTML解析C# 包涵注释,全中文
- C#备忘录+完整源代码
- c#使用sip协议实现呼叫
- C#使用引擎调用MATLAB神经网络工具箱
- 百度云C#开发实战1200例书和光盘
- C# C/S平台软件自动更新程序 SQLServer
- C# socket心跳
- C#最简单最完整的webservice能打log,配
评论
共有 条评论