using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TIASshot {
public partial class PreviewMonitor : Form {
private Point _location;
private Size _size = new Size(0, 0);
private Bitmap _dispBuf;
private bool _isUpdateBuf = false;
public bool IsShown => (_size.Width > 0);
/// <summary>
/// プレビューウィンドウのコンストラクタ
/// </summary>
public PreviewMonitor() {
InitializeComponent();
// プレビューウィンドウの位置とサイズを取得
foreach (var scr in Screen.AllScreens) {
if (scr.Primary) continue; // プライマリスクリーンは除外
if (scr.Bounds.Width <= Config.GetInt("Shot/PreviewMonitorWidth")) {
_location = scr.Bounds.Location;
_size = scr.Bounds.Size;
}
}
}
/// <summary>
/// プレビューウィンドウのロードイベント
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PreviewMonitor_Load(object sender, EventArgs e) {
// プレビューウィンドウの位置とサイズを設定
Location = _location;
Size = _size;
}
/// <summary>
/// プレビューウィンドウの表示状態を更新
/// </summary>
/// <param name="image"></param>
public void UpdateImage(Bitmap image) {
_dispBuf = image;
_isUpdateBuf = true;
Invalidate();
}
/// <summary>
/// プレビューウィンドウの再描画イベント
/// </summary>
/// <param name="bmp"></param>
private void PreviewMonitor_Paint(object sender, PaintEventArgs e) {
if (!IsShown || !_isUpdateBuf || _dispBuf == null) return;
picPreview.Image?.Dispose();
picPreview.Image = _dispBuf;
_isUpdateBuf = false;
}
}
}