【C#学习笔记】载入图片并居中
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog dig = new OpenFileDialog(); if (dig.ShowDialog() == DialogResult.OK) { pictureBox1.Image = Image.FromFile(dig.FileName); pictureBox1.Top = (ClientRectangle.Height - pictureBox1.Height) / 2; pictureBox1.Left = (ClientRectangle.Width - pictureBox1.Width) / 2; } } } }