Skip to content

Instantly share code, notes, and snippets.

@nhoxbypass
Created December 11, 2017 14:22
Show Gist options
  • Select an option

  • Save nhoxbypass/1a37750c25c21aac441c331a69505dfb to your computer and use it in GitHub Desktop.

Select an option

Save nhoxbypass/1a37750c25c21aac441c331a69505dfb to your computer and use it in GitHub Desktop.
namespace Picture_Viewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Cài đặt thuộc tính pictureBox
pictureBox1.ImageLocation = "http://1.bp.blogspot.com/-ZskeiTa6Rig/VZwjEuEQPqI/AAAAAAAAAM0/VK5Im7Cfu3s/s1600/cooltext125983511023412.png";
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
// Cài đặt thuộc tính OFD
openFileDialog1.Title = "Select Picture";
openFileDialog1.Filter = "Windows Bitmap|*.bmp|JPEG Image|*.jpg|All Files|*.*";
}
private void button1_Click(object sender, EventArgs e)
{
// Show hộp thoại open file ra
// Nhận kết quả trả về qua biến kiểu DialogResult
DialogResult result = openFileDialog1.ShowDialog();
//Kiểm tra xem người dùng đã chọn file chưa
if(result == DialogResult.OK)
{
// Lấy hình ảnh
Image img = Image.FromFile(openFileDialog1.FileName);
// Gán ảnh
pictureBox1.Image = img;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment