c# 돋보기 프로그램 [윈폼]

Posted by 컴스퍼거
2020. 7. 29. 00:33 프로그래밍/C#
반응형

인터넷으로 작은글씨를 볼 필요성 때문에 C#으로 돋보기 프로그램을 만들게 되었습니다.


소스코드

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace magnifier
{
    class LibosMagnifier
    {
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
    int curX = Cursor.Position.X;
    int curY = Cursor.Position.Y;

    int screenWidth = 50;
    int screeHeight = 50;

    Size size = new Size(screenWidth, screeHeight);
    Bitmap bitmap = new Bitmap(size.Width, size.Height);

    double rate = 2.0;

    Graphics graphic = Graphics.FromImage(bitmap);
    graphic.CopyFromScreen(curX - (screenWidth / 2), curY - (screeHeight / 2), 0, 0, size); // 화면 캡쳐

    int zoominWidth = (int)(screenWidth * rate);
    int zoominHeight = (int)(screeHeight * rate);

    Bitmap zoomin = new Bitmap(zoominWidth, zoominHeight);

    for (int i = 0; i < zoominWidth; i++)
    {
        for (int j = 0; j < zoominHeight; j++)
        {
            int row = (int)(i / rate);
            int col = (int)(j / rate);
            zoomin.SetPixel(i, j, bitmap.GetPixel(row, col));
        }
    }
}
    }
}

폼 구성

PictureBox 하나로만 구성되어있습니다.


자동 크기 조절이 되게 이벤트 헨들러를 손봤습니다.

pictureBox1입니다. Dock를 Fill 속성으로 변경했습니다.


다음은 Form1입니다. AutoSize를 True로 AutoSizeMode를 GrowOnly로 변경했습니다. 그리고 FormBorderStyle을 SizableToolWindow로 맞추면 됩니다.

사용법

마우스 휠을 키우면 확대, 줄이면 픽셀 크기가 감소 됩니다. 또한 창크기를 변환 할수 있어서 어떤 화면의 글자든 확대해서 볼 수 있습니다.

프로그램 다운


버젼2

최소화가 안먹혀서 새로이 올립니다.


반응형