Boki wrote:
> [...]
> (1) Declare a public method:
>
> /* function of form1 */
> public void active_this_form()
> {
> this.WindowState = FormWindowState.Normal;
> this.Focus();
> this.Show();
> }
>
> After call this function from form2, form1 keeps minimized.
This should work, or at least something similar to it. Have you tried
putting the Focus() and/or Show() calls before the WindowState call?
Also, if you can call a public method on form1, why can't you just set
the property directly if you have to? In either case, you need a
reference to the form instance. If you can do one, you should be able
to do the either.
This is a good example of why you should post a complete-but-concise
example of code that reliably reproduces your problem. The above isn't
that. With a complete-but-concise example of code that reliably
reproduces the problem, it would be easier for someone to actually
compile your code and see what's going on.
> (2) Use reference:
>
> /* Code in form1 */
> public partial class Form1 : Form
> {
> public static Form1 staticVar = null;
> ....
>
> /* Code in form2 */
> Form1.staticVar.WindowState = FormWindowState.Normal;
>
> This code can't compile.
Why not? What error do you get? How do you initialize "staticVar"?
> The second method can modify a variable, but seems can't modify the
> properties of form ?
There's no reason you shouldn't be able to modify a writeable property
of a Form instance, regardless of how you do it. You have jumped to an
incorrect conclusion based on some problem (but you haven't described
the problem completely, so it's impossible to say where the error in
your conclusion came from).
That said, this "staticVar" method is pretty bad, unless you really do
have a singleton form and you use exactly the code that Karthik posted
(that is, with a private constructor, so that you can only instantiate
the form through the Instance property).
You could also use the code that Leon posted, but as I mentioned in my
comments to your #1 attempt, it doesn't seem as though getting at the
form1 instance is actually your problem, since you apparently can call
the public method you created.
Again, a concise-but-complete sample of code would go a long way to
making your question make more sense here.
Pete
|