C
chau_fai
I have a window Form called "Form2". There is only one button and a
panel returned from a static method of the "Coord" in this form.
In the panel returned, there is a button that can choose image from
"OpenFileDialog" and then display it in a picturebox.
This actually works properly before the button1 is clicked.
Button1 is a button to open a new form and again it gets a panel
returned from the static method inside "Coord" and perform the same
function as methioned above.
Now, the new form being opened by Button1 works properly. It can show
a image selected by the openfiledialog. When this form is closed and
return back to "Form2" .... the controls in the original panel doesn't
work properly. The picturebox display nothing although a file is
selected. It seems that the event is partly fired only. But the
Button1 in the Form2 still works properly that can open a new form and
the new form is working very well also.
Actually .... i don't know what is the problem ....
//Form 2
private void Form2_Load(object sender, System.EventArgs e)
{
this.Controls.Add(Coord.ReturnPanel();
}
private void button1_Click(object sender, System.EventArgs e)
{
Form a = new Form();
a.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
a.ClientSize = new Size(790,550);
a.Controls.Add(Coord.ReturnPanel());
//a.Location = new System.Drawing.Point(500, 500);
a.StartPosition = FormStartPosition.CenterScreen;
a.Name = "frmAddMember";
a.FormBorderStyle = FormBorderStyle.Fixed3D;
a.Text = "New Member";
a.ShowDialog();
}
//Coord
private static Button test;
private static PictureBox picTest;
private static Panel pan;
private static OpenFileDialog open;
public static Panel ReturnPanel()
{
pan = new Panel();
test = new Button();
picTest = new PictureBox();
open = new OpenFileDialog();
pan.Location = new System.Drawing.Point(8, 8);
pan.Name = "panelMember";
pan.Size = new System.Drawing.Size(784, 536);
pan.Controls.Add(test);
pan.Controls.Add(picTest);
picTest.Location = new System.Drawing.Point(552, 72);
picTest.Name = "this.picUser";
picTest.Size = new System.Drawing.Size(192, 200);
picTest.TabIndex = 1;
picTest.TabStop = false;
test.Location = new System.Drawing.Point(696, 24);
test.Size = new System.Drawing.Size(24, 24);
test.Click += new System.EventHandler(btn_Click);
return pan;
}
private static void btn_Click(object sender, System.EventArgs e)
{
open.Title = "Select a image file";
open.Filter = "Image Files(*.BMP;*.JPG
|*.BMP;*.JPG;
if(open.ShowDialog() == DialogResult.OK)
{
Bitmap userImage = new Bitmap(open.FileName);
picTest.Image = (Image)userImage;
}
}
Any Helps will be appreciated ~~
panel returned from a static method of the "Coord" in this form.
In the panel returned, there is a button that can choose image from
"OpenFileDialog" and then display it in a picturebox.
This actually works properly before the button1 is clicked.
Button1 is a button to open a new form and again it gets a panel
returned from the static method inside "Coord" and perform the same
function as methioned above.
Now, the new form being opened by Button1 works properly. It can show
a image selected by the openfiledialog. When this form is closed and
return back to "Form2" .... the controls in the original panel doesn't
work properly. The picturebox display nothing although a file is
selected. It seems that the event is partly fired only. But the
Button1 in the Form2 still works properly that can open a new form and
the new form is working very well also.
Actually .... i don't know what is the problem ....
//Form 2
private void Form2_Load(object sender, System.EventArgs e)
{
this.Controls.Add(Coord.ReturnPanel();
}
private void button1_Click(object sender, System.EventArgs e)
{
Form a = new Form();
a.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
a.ClientSize = new Size(790,550);
a.Controls.Add(Coord.ReturnPanel());
//a.Location = new System.Drawing.Point(500, 500);
a.StartPosition = FormStartPosition.CenterScreen;
a.Name = "frmAddMember";
a.FormBorderStyle = FormBorderStyle.Fixed3D;
a.Text = "New Member";
a.ShowDialog();
}
//Coord
private static Button test;
private static PictureBox picTest;
private static Panel pan;
private static OpenFileDialog open;
public static Panel ReturnPanel()
{
pan = new Panel();
test = new Button();
picTest = new PictureBox();
open = new OpenFileDialog();
pan.Location = new System.Drawing.Point(8, 8);
pan.Name = "panelMember";
pan.Size = new System.Drawing.Size(784, 536);
pan.Controls.Add(test);
pan.Controls.Add(picTest);
picTest.Location = new System.Drawing.Point(552, 72);
picTest.Name = "this.picUser";
picTest.Size = new System.Drawing.Size(192, 200);
picTest.TabIndex = 1;
picTest.TabStop = false;
test.Location = new System.Drawing.Point(696, 24);
test.Size = new System.Drawing.Size(24, 24);
test.Click += new System.EventHandler(btn_Click);
return pan;
}
private static void btn_Click(object sender, System.EventArgs e)
{
open.Title = "Select a image file";
open.Filter = "Image Files(*.BMP;*.JPG

if(open.ShowDialog() == DialogResult.OK)
{
Bitmap userImage = new Bitmap(open.FileName);
picTest.Image = (Image)userImage;
}
}
Any Helps will be appreciated ~~