Close/Hide a Tool Window causes a 'System . NullReferenceExc

DockableWindow/TabStripPanel for Windows Forms Forum

Posted 19 years ago by tony_coupland
Avatar
Hi,

I have a main application which contains the DocumentManger, I have a child form (inheriting UserControl) contained in a non-dockable toolwindow which display as a dialog box. Is it possible to close (hide) this dialog box (toolwindow) from itself?

I have a command button on the dialog which sends a message to the mainform (with itself as a parameter) which then looks up the ToolWindow assoicated and sends the hide command to it. The system then causes the exception 'System.NullReferenceException' within the control.

From the other threads on here it seems that the child windows are closed from the thread running the main form (with the DocumentManager), is this where my problem comes from?

I can put together a sample set of code to illustrate this if it doesnt make sence.

Regards,
Tony Coupland

Comments (5)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Tony,

It probably would help if you could put together a sample app and send that to us.


Actipro Software Support

Posted 19 years ago by tony_coupland
Avatar
In the main form I have the following:

    public class MainForm : System.Windows.Forms.Form
    {

        public MainForm()
        {
            InitializeComponent();
        }

        public void HideForm ( Controls.DialogWindow frm )
        {
            if ( frm is Controls.DialogWindow )
            {
                int iIndex = dwManager.ToolWindows.IndexOf ( frm.Key );
                if ( iIndex > -1 )
                {
                    DWToolWindow dwtoolwindow = dwManager.ToolWindows[iIndex];
                    if ( dwtoolwindow != null )
                        dwtoolwindow.Hide();
                }
            }
        }
    }
and in the connection dialog I have the following close code.

    public class ConnectForm : Controls.DialogWindow 
    {
        public ConnectForm()
        {}

        private void btnClose_Click(object sender, System.EventArgs e)
        {
            MainForm.HideForm ( this );
        }
    }
Obviously there is more perifery than this but hopefully this should highlight the problem.

After the exception, the code halts on the 'dwtoolwindow.Hide();' line quoting a NullReference exception within the ActiPro control.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Can you also post the stack trace?


Actipro Software Support

Posted 19 years ago by tony_coupland
Avatar
<IMG SRC="http://www.marjuan.com/forum/uploads/post-1-1107939712.jpg">

I'm not sure if this gives you any more details but here it is anyway.

I thought the problem could be to do with the threads that each dialog is running on so I repalced the code in the HideForm function to add the form to a queue and then the queue is monitored by a timer whihc closes any forms waiting on the queue. However, this doesnt fix the problem.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I was hoping to see a stack trace including our methods. Would it be possible for you to throw together a quick application project that duplicates this problem? That way we can run it in debug mode.


Actipro Software Support

The latest build of this product (v2.0.0208) was released 19 years ago, which was after the last post in this thread.