أخواني اريد أعرف ما الخطأ في هذا الكود:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Button btn1;
PictureBox Pic;
public Form1()
{
Button btn1 = new Button();
btn1.Text = "Load";
btn1.Top = 10;
btn1.Left = 10;
btn1.Click += new System.EventHandler(this.OnLoadClick);
PictureBox Pic = new PictureBox();
Pic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
Pic.Size = Pic.Size - btn1.Size;
Pic.Width = this.Width / 3;
Pic.Height = this.Height / 3;
Pic.Left = (this.Width - Pic.Width) / 2;
Pic.Top = (this.Height - Pic.Height) / 2;
this.Controls.Add(btn1);
this.Controls.Add(Pic);
}
private void OnLoadClick(object sender, System.EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open Photo";
dlg.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
Pic.ImageLocation = dlg.FileName;
}
}
static void Main()
{
Application.Run(new Form1());
}
}
}