c#图片浏览器源码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
?using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 图片浏览器
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
int currentPictureIndex;
Point oldPosition = new Point();
private void btnSelectPicture_Click(object sender, EventArgs e)
{
if (ofdSelectPicture.ShowDialog() == DialogResult.OK)
{
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileNames[0]);
currentPictureIndex = 0;
}
}
private void btnQuit_Click(object sender, EventArgs e)
{
Close();
}
private void btnNext_Click(object sender, EventArgs e)
{
if (currentPictureIndex < ofdSelectPicture.FileNames.Length - 1)
currentPictureIndex++;
else
currentPictureIndex = 0;
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileNames[currentPictureIndex]);
}
private void btnPre_Click(object sender, EventArgs e)
{
if (currentPictureIndex > 0)
currentPictureIndex--;
else
currentPictureIndex = ofdSelectPicture.FileNames.Length - 1;
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileNames[currentPictureIndex]);
}
private void btnZoomIn_Click(object sender, EventArgs e)
{
picShowPicture.Dock = DockStyle.None;
picShowPicture.Height = Convert.ToInt32(picShowPicture.Height * 1.5);
picShowPicture.Width = Convert.ToInt32(picShowPicture.Width * 1.5);
picShowPicture.Top = (panel1.Height - picShowPicture.Height) / 2;
picShowPicture.Left = (panel1.Width - picShowPicture.Width) / 2;
}
private void btnZoomOut_Click(object sender, EventArgs e)
{
picShowPicture.Dock = DockStyle.None;
picShowPicture.Height = Convert.ToInt32(picShowPicture.Height * 0.5);
picShowPicture.Width = Convert.ToInt32(picShowPicture.Width * 0.5);
picShowPicture.Top = (panel1.Height - picShowPicture.Height) / 2;
picShowPicture.Left = (panel1.Width - picShowPicture.Width) / 2;
}
private void btnFullScreen_Click(object sender, EventArgs e)
{
picShowPicture.Width = panel1.Width;
picShowPicture.Height = panel1.Height;
picShowPicture.Top = (panel1.Height - picShowPicture.Height) / 2;
picShowPicture.Left = (panel1.Width - picShowPicture.Width) / 2;
}
private void MainForm_Resize(object sender, EventArgs e)
{
picShowPicture.Top = (pa
nel1.Height - picShowPicture.Height) / 2;
picShowPicture.Left = (panel1.Width - picShowPicture.Width) / 2;
}
private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '+')
{
btnZoomIn_Click(null, null);
}
if (e.KeyChar == '-')
{
btnZoomOut_Click(null, null);
}
if (e.KeyChar == 'N' || e.KeyChar == 'n')
{
btnNext_Click(null, null);
}
if (e.KeyChar == 'P' || e.KeyChar == 'p')
{
btnPre_Click(null, null);
}
}
private void picShowPicture_MouseDown(object sender, MouseEventArgs e)
{
oldPosition = Cursor.Position;
}
private void picShowPicture_MouseMove(object sender, MouseEventArgs e)
{
sslx.Text = e.X.ToString();
ssly.Text = e.Y.ToString();
//sslx.Text = Cursor.Position.X;
//ssly.Text = Cursor.Position.Y;
if (e.Button == MouseButtons.Left)
{
picShowPicture.Dock = DockStyle.None;
picShowPicture.Left += Cursor.Position.X - oldPosition.X;
picShowPicture.Top += Cursor.Position.Y - oldPosition.Y;
oldPosition = Cursor.Position;
}
}
}
}