Accessing one Form from Another

  • Thread starter Thread starter Eric B.
  • Start date Start date
E

Eric B.

I am going crazy. Trying to create a secondary form, do a .DrawToBitmap of
the WebBrowser on it and send the bitmap to a PictureBox on the first form.

My problem is I cannot seem to create a method on form2 that I can access on
form1.

I tried using the advice from this link:

http://stackoverflow.com/questions/8566/best-way-to-access-a-control-on-another-form-in-c

I added this property code to form2:

public boolean ControlIsVisible
{
get { return control.Visible; }
set { control.Visible = value; }
}

Just to see if I could access it from form1, no go.

What am I doing wrong? Please Help!

Eric B.
 
What am I doing wrong? Please Help!

Are you creating an instance of Form2 from within Form1? e.g.:

Form2 frm2 = new Form2();

if so frm2.ControlIsVisible should work. If they are completely
independent forms it will be rather more complex.
 
You need to post the code that creates form2 and then tries to access this
property.

My bet is that you are doing this

Form form2 = new Form2();

rather than this

Form2 form2 = new Form2();
 
Peter Duniho said:
No. Assuming Pete M.'s guess about your code was correct (note that since
you still haven't bothered to post any code, all we can do is
guess...that's not a very good way for you to get actual answers to your
question), then you did in fact create an instance of Form2. But you
assigned it to a variable that is typed as Form, and with that variable
you can only access things in the Form class.


1) We can assume his assumption was correct because it solved my problem.
Usually when a problem is solved by a given solution we consider the
solution was in fact correct.

2) I did post some code, perhaps you need glasses as well?

3) There was no need to further post code because as I suspected my problem
was able to be solved by describing the circumstances involved. It was a
newbie mistake, that's all.

4) Your explanation appears to just be a long-winded way of saying the same
thing I did, that I *in effect* created an instance of Form instead of a
Form2.

Eric B.
 
Peter Duniho said:
You never stated that it actually solved your problem. There was no way
for anyone to make that inference.

I suppose "Yes! I see it now!" was far too subtle for you. :/
Sorry, I should have been more specific: "you still haven't bothered to
post any of the _relevant_ code". That is, you complained that something
didn't work, but you didn't show any of the code actually trying to use
what didn't work.

Yes, you posted code. But the code you posted had nothing to do with your
problem.

The code I posted *was* the code that didn't work. Are you pretending to be
this thick?

Eric B.
 
Back
Top