728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Media;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 사운드 플레이어
/// </summary>
private SoundPlayer soundPlayer = new SoundPlayer();
/// <summary>
/// 위치 설정 가능 여부
/// </summary>
bool canSetLocation = true;
/// <summary>
/// 폼 위치
/// </summary>
private Point formLocation;
/// <summary>
/// 폼 크기
/// </summary>
private Size formSize;
/// <summary>
/// 이미지 저장 가능 여부
/// </summary>
bool canSaveImage = false;
/// <summary>
/// 그래픽스
/// </summary>
private Graphics graphics = null;
/// <summary>
/// 비트맵
/// </summary>
private Bitmap bitmap = null;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
LocationChanged += Form_LocationChanged;
KeyPress += Form_KeyPress;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 폼 위치 변경시 처리하기 - Form_LocationChanged(sender, e)
/// <summary>
/// 폼 위치 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_LocationChanged(object sender, EventArgs e)
{
if(this.canSetLocation == true)
{
this.formLocation = Location;
this.formSize = Size;
}
}
#endregion
#region 폼 키 PRESS시 처리하기 - Form_KeyPress(sender, e)
/// <summary>
/// 폼 키 PRESS시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == 'c' || e.KeyChar == 'C')
{
this.canSetLocation = false;
this.canSaveImage = true;
FormBorderStyle = FormBorderStyle.None;
Location = new Point(0, 0);
Size = Screen.PrimaryScreen.Bounds.Size;
Opacity = 0.0;
Rectangle rectangle = Screen.PrimaryScreen.Bounds;
this.bitmap = new Bitmap(rectangle.Width, rectangle.Height);
this.graphics = Graphics.FromImage(this.bitmap);
this.graphics.CopyFromScreen(PointToScreen(new Point(0,0)), new Point(0, 0), rectangle.Size);
this.pictureBox.Image = this.bitmap;
this.soundPlayer.SoundLocation = @"..\..\wav\capture.wav";
this.soundPlayer.Play();
FormBorderStyle = FormBorderStyle.FixedSingle;
Location = formLocation;
Size = formSize;
Opacity = 100.0;
this.canSetLocation = true;
}
else if(e.KeyChar == 'e' || e.KeyChar == 'E')
{
this.soundPlayer.SoundLocation = @"..\..\wav\ereser.wav";
this.soundPlayer.Play();
this.canSaveImage = false;
this.pictureBox.Image = null;
}
else if(e.KeyChar == 's' || e.KeyChar == 'S')
{
if(this.canSaveImage == true)
{
using(SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.OverwritePrompt = true;
saveFileDialog.FileName = "capture";
saveFileDialog.Filter = "Image file(*.png)|*.png";
DialogResult dialogResult = saveFileDialog.ShowDialog();
if(dialogResult == DialogResult.OK)
{
this.bitmap.Save(saveFileDialog.FileName, ImageFormat.Png);
}
}
}
else
{
MessageBox.Show("캡처한 화면이 없습니다.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 컨트롤 바인딩 사용하기 (0) | 2017.06.10 |
---|---|
[C#/WINFORM] Image 클래스 : 이미지 크기 조정하기 (0) | 2017.05.26 |
[C#/WINFORM] 트레이 아이콘 사용하기 (0) | 2017.05.20 |
[C#/WINFORM] 워터마크 사용하기 (0) | 2017.05.05 |
[C#/WINFORM] 후킹을 사용해 화면 잠그기 (0) | 2017.05.05 |
[C#/WINFORM] UserControl 클래스 : 이미지 버튼 사용하기 (0) | 2017.05.04 |
[C#/WINFORM] 토글 스위치 사용하기 (0) | 2017.05.01 |
[C#/WINFORM] 더블 버퍼링 설정하기 (0) | 2017.04.30 |
[C#/WINFORM] Clipboard 클래스 : 엑셀 데이터 붙여넣기 (0) | 2017.04.03 |
[C#/WINFORM] 외곽선 텍스트 그리기 (0) | 2017.02.01 |
댓글을 달아 주세요