I need to write a non-mdi winforms application using c# and .net framework
2.0 that keeps track of open windows and binds to a control on the main
application or shell. I can't use a MDI application becuase I need the
application to support dual monitors where I can have multiple windows open
on both screens.
Any suggestion on how I can accomplish this.
Thanks.
Mehdi - 15 Jun 2006 16:43 GMT
> I need to write a non-mdi winforms application using c# and .net framework
> 2.0 that keeps track of open windows and binds to a control on the main
[quoted text clipped - 3 lines]
>
> Any suggestion on how I can accomplish this.
There are several possibilties. One of them would be to create a class
deriving from Form which would have a static property returning the list of
windows (forms) of your application. The constructor of this class would
add itself to this static list of windows. Then, whenever you create a new
Form in your application, derive from your custom Form class instead of
using the standard .NET Form class so that each time you instanciate a new
window, it automatically adds itself to the list of windows of your
application.
Linda Liu [MSFT] - 16 Jun 2006 07:04 GMT
Hi Brian,
Thank you for posting.
I think the solution of Mehdi is good. What I want to supplement to the
Mehdi's solution is that you should remove the form instance from the
static list of forms when the form instance is closed.
Here is a sample for you.
// the BaseForm is a base class for all other form classes in the project
public partial class BaseForm : Form
{
public BaseForm()
{
InitializeComponent();
_InstanceList.Add(this);
}
private void BaseForm_FormClosed(object sender, FormClosedEventArgs
e)
{
_InstanceList.Remove(this);
}
private static Collection<BaseForm> _InstanceList = new
Collection<BaseForm>();
public static Collection<BaseForm> InstanceList
{
get { return _InstanceList; }
}
}
If there's anything unclear, don't hesitate to get in touch. I look forward
to your reply.
Sincerely,
Linda Liu
Microsoft Online Community Support
====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================