• 大小: 41KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: C#
  • 标签: C#  放大镜  鼠标跟随  

资源简介

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个文件信息

评论

共有 条评论