Hiện link ảnh lên textbox trong c#

Mọi người cho em hỏi làm sao để em lấy được link ảnh đổ vào textbox trong sự kiện TextChanged được, textbox em để chố độ Enabled=false.
dưới đây là đoạn code load ảnh của em vào pictureBox:

private void btnMoAnh_Click(object sender, EventArgs e)
{
OpenFileDialog dlgOpen = new OpenFileDialog();
dlgOpen.Filter = "Bitmap( *.bmp)|* .bmp|Gif( *.gif) |* .gif|Allfiles( *.* ) |  *.*  ";
dlgOpen.InitialDirectory = “D:\ảnh\save”;
dlgOpen.FilterIndex = 2;
dlgOpen.Title = “Chọn ảnh để hiển thị”;
if (dlgOpen.ShowDialog() == System.Windows.Forms.DialogResult.OK)
pictureBox1.Image = Image.FromFile(dlgOpen.FileName);
else
MessageBox.Show(“You clicked Cancel”, “Open Dialog”,
MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(pictureBox1.ImageLocation);
}

hoibai

thay vì enabled = false, bạn có thể set readonly = true là user không sửa được mà vẫn có thể select copy các kiểu.

textBox1.Text = dlgOpen.FileName;
4 Likes

Cám ơn ạ, mình làm được rồi!

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?