This is a migrated thread and some comments may be shown as answers.

MDI Child Form System Exception

9 Answers 455 Views
Form
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 16 Jun 2017, 04:26 PM

I doubt that this is an issue with the WinForms controls but I'll ask anyway in case anyone has experienced this problem (and I haven't found any solution searching the web).  My project is MDI with seven child forms so far.  After a few months of development I finally experienced a problem when I select several of my menu options (launch several child forms).  It doesn't matter what the order I select the menu options; the third menu option, whichever option that happens to be, gets a System.NullReferenceException.

The code for each menu option is this pattern:

private void miDULAudit_Click(object sender, EventArgs e)
{
    if (objDULAudit == null)
    {
        objDULAudit = new frmDULAudit();
        objDULAudit.MdiParent = this;
        objDULAudit.FormHiding += new EventHandler(ChildFormHiding);
    }
    objDULAudit.Show();
    objDULAudit.BringToFront();
    objDULAudit.Activate();
    objDULAudit.WindowState = FormWindowState.Maximized;
}

 

The error happens at objDULAudit.Show(); (in this code example).  

System.NullReferenceException was unhandled
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 

 

I stepped through every line of code (as the child form instantiates) trying to run into the problem but I have not been successful.

Any ideas?

Thank you,

Gary

 

 

9 Answers, 1 is accepted

Sort by
0
Jay
Top achievements
Rank 1
answered on 16 Jun 2017, 06:37 PM

Update: I discovered that if the child forms are not maximized then this System.Exception doesn't happen.  For every menu option event handler I added a method to set all child forms to the normal window state and I can open every option without getting that error.  While I still want to fix the real problem, this work around helps.  There is the visual effect of the child form(s) switching from maximized to standard and then the selected child form maximizing.  I'd like to hide that.

 

But I'm still searching for the real problem.

 

0
Dimitar
Telerik team
answered on 19 Jun 2017, 06:47 AM
Hello Gary,

We had a report for an exception in the same method with a similar scenario. It appears however that it is not connected to our controls and the issue is in the .NET code. You can check the comments on our public item for detailed information: UI for Winforms Feedback Portal - FIX. RadForm - Exception when showing maximized MDI children with a lot of gauges.

I hope this will be useful. 

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jay
Top achievements
Rank 1
answered on 19 Jun 2017, 02:08 PM

Dimitar,

Thank you.  That is helpful; my work around is the solution and the problem is within .Net.  I couldn't find any confirmation in my searching on the web.  Your link is what I was looking for.

Thank you,

Gary

0
Dimitar
Telerik team
answered on 20 Jun 2017, 06:43 AM
Hello Gary,

I am glad that this information was useful to you. Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Roger
Top achievements
Rank 2
Iron
Iron
Iron
answered on 14 Mar 2024, 04:41 PM

I believe this is still an issue.  I cannot make the work around work. 

 I tried to set my form window state to Normal but am still getting the error.

I am on .Net 4.8 and Telerik 2024.1.312

0
Nadya | Tech Support Engineer
Telerik team
answered on 19 Mar 2024, 10:37 AM

Hello, Roger,

Thank you for writing.

The issue discussed in this thread regarding showing maximized MDI children forms is not related to our controls and the issue is in the .NET code. You can see that the item's status is set to "Declined" due to these reasons. 

However, if you are having difficulties using RadForm it would be greatly appreciated if you provide more information about the case that you have. Basically, you should be able to set the RadForm.WindowState to Normal, Maximized, or Minimized. 

Please let me know if you need further assistance.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 19 Mar 2024, 01:16 PM

 

 

 

Her is my code..  If I run this code as one of the 1st forms to open it works as expected.

But if it's the 3rd or more form opened, I get the error Object reference not set to an instance of an object on the Show.

As you can see below, I have set the form to be normalized and still get the error.


namespace FirmDocumentSystem
{
    public partial class netDocsSystemInfo : Telerik.WinControls.UI.RadForm
{
.....
netDocsSystemInfo frmndSystemInfo = new netDocsSystemInfo();
frmndSystemInfo.Text = "Net Docs System Info";
frmndSystemInfo.WindowState = FormWindowState.Normal;
frmndSystemInfo.MdiParent = this;
frmndSystemInfo.ThemeName = Properties.Settings.Default.DefaultTheme;
frmndSystemInfo.Show();

0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Mar 2024, 09:51 AM

Hello, Roger,

Thank you for the provided code snippet.

I used it in my test project, however, I am not able to get the error that you described. I am able to create many child forms. Please refer to the attached gif file that demonstrates the result on my end. Am I missing something? Can you please specify if I need to do something else to reproduce the error. In addition, is it possible to specify which Telerik version you use?

Please let me know if I can assist you further.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 21 Mar 2024, 11:41 AM

In your example none of your forms are maximized after they are shown.  In my situation my forms are maximized after showing.

Please try maximizing your forms after loading, then see how many child forms you can have.

Could you then post your code.

Thanks,

0
Roger
Top achievements
Rank 2
Iron
Iron
Iron
answered on 21 Mar 2024, 12:35 PM

 

I did find a solution to this issue.  If I loop through each child form and set windowstate to normal, then show the new window.  Everything seems to work as expected.

After showing the window I then set that child windowstate to maximized.

 

You would think the MDI Parent could be doing this automatically so we would not have to manage this.

 

Here is the Code:


 Cursor.Current = Cursors.WaitCursor;
 int intIndexChild;

 foreach (Form f in this.MdiChildren)
 {
     f.WindowState = FormWindowState.Normal;
 }


 if (!ExistInParent(typeof(netDocsSystemInfo), out intIndexChild))
 {
     try
     {
         netDocsSystemInfo frmndSystemInfo = new netDocsSystemInfo();
         frmndSystemInfo.WindowState = FormWindowState.Normal;
         frmndSystemInfo.MdiParent = this;
         frmndSystemInfo.Text = "Net Docs System Info";
         frmndSystemInfo.ThemeName = Properties.Settings.Default.DefaultTheme;
         frmndSystemInfo.Show();
         frmndSystemInfo.WindowState = FormWindowState.Maximized;
     }
     catch (Exception e)
     {
         LogHelper.Log(LogTarget.Database,$"Error Opening up NetDocSystemInfo form.  Error {e.Message}");
     }   
 }
 else
 {
     foreach (Form f in this.MdiChildren)
     {
         if (f.Text == "Net Docs System Info")
         {
             f.Activate();
             f.WindowState = FormWindowState.Maximized;
         }
     }
 }
 Cursor.Current = Cursors.Default;

0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Mar 2024, 03:09 PM

Hello, Roger,

It seems that you managed to work around the problem, but I still cannot reproduce it on my end.

I changed my code to show maximized child forms, but I am still not able to get an error. I am providing my test project for your reference. Can you give it a try and let me know if you can reproduce the problem there?

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Form
Asked by
Jay
Top achievements
Rank 1
Answers by
Jay
Top achievements
Rank 1
Dimitar
Telerik team
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Nadya | Tech Support Engineer
Telerik team
Share this question
or