private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog res = new OpenFileDialog();
res.Filter = "Image Files|*.jpg;*.jpeg;*.png;";
if (res.ShowDialog() == DialogResult.OK)
{
var filePath = res.FileName;
var fileName = Path.GetFileName(filePath); // get only the file name from the full path
textBox1.Text = fileName; // display the file name in the textbox
pictureBox1.Image = Image.FromFile(filePath);
OnPictureChanged(EventArgs.Empty);
}
}
[Localizable(true)]
public Image Image
{
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
get
{
return pictureBox1.Image;
}
set
{
pictureBox1.Image = value;
OnPictureChanged(EventArgs.Empty);
if (value != null)
{
var fileName = Path.GetFileName(value.ToString()); // get only the file name from the full path
textBox1.Text = fileName; // display the file name in the textbox
}
else
{
textBox1.Text = ""; // clear the textbox if the image is null
}
Invalidate();
}
}