图片查看器,防止boss
1 effect

KEY UP DOWN ----- Picture content move
KEY LEFT RIGHT ------Turn page
2 code
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; namespace LoadImage { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void pictureBox1_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void panel2_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up) { pictureBox1.Top = pictureBox1.Top-60;//设置y坐标. } else if (e.KeyCode == Keys.Down) { pictureBox1.Top = pictureBox1.Top + 60;//设置y坐标. } else if (e.KeyCode == Keys.Left) { if (fileIndex == 0 || files.Count == 0) return; else { fileIndex = fileIndex - 1; pictureBox1.Load(files[fileIndex].ToString()); } } else if (e.KeyCode == Keys.Right) { if (fileIndex>files.Count-2) return; else { fileIndex = fileIndex + 1; pictureBox1.Load(files[fileIndex].ToString()); } } else if (e.KeyCode == Keys.Enter) { this.WindowState = FormWindowState.Minimized; } else if (e.KeyCode == Keys.Space) { this.WindowState = FormWindowState.Minimized; } else if(e.KeyCode==Keys.D) { if(this.FormBorderStyle == FormBorderStyle.None) this.FormBorderStyle = FormBorderStyle.FixedSingle; else this.FormBorderStyle = FormBorderStyle.None; } } public static string CurrentFilePath = ""; public static string CurrentFileName = ""; public ArrayList files = new ArrayList(); public int fileIndex = 0; private void Form1_Load(object sender, EventArgs e) { this.FormBorderStyle = FormBorderStyle.None; this.ShowInTaskbar = false; CurrentFilePath = System.Threading.Thread.GetDomain().BaseDirectory; DirectoryInfo TheFolder = new DirectoryInfo(CurrentFilePath); var al = Directory.GetFiles(CurrentFilePath, "*.*", SearchOption.TopDirectoryOnly) .Where(s => s.EndsWith(".bmp") || s.EndsWith(".jpg")); foreach (string str in al) { files.Add(str); } if (files.Count > 0) pictureBox1.Load(files[fileIndex].ToString()); } } }
posted on 2019-09-11 16:32 developer1980 阅读(100) 评论(0) 收藏 举报
浙公网安备 33010602011771号