Change the title of a NUIDocument causes resize/reposition


https://www.nevron.com/Forum/Topic6962.aspx
Print Topic | Close Window

By Craig Swearingen - 12 Years Ago

I have a DocumentViewStyle application set to MdiStandard on the 11.12.14.12 build.  I need to be able to change the frame title of my documents after they've been created on certain possible user events.  Using the key I've been able to find the NUIDocument which needs changing and I can set the Text property of it to my new title.  When I do this the frame title does change to the new text but the document is moved to the position where it was first created and its size is set to what it was when it was first created.

I don't see another option.  How can I change just the title of the document frame alone?

By Nevron Support - 12 Years Ago
Hi Craig,

With the latest version if you find the desired document by its key like this:
NUIDocument doc = nDockManager1.DocumentManager.GetDocumentByKey(documentKey);
and then change its text property:

if (doc != null)
{
   doc.Text = newTextValue;
}

it should change the text of the document title without changing its position.
By Craig Swearingen - 12 Years Ago

The code you provided is exactly what I am doing.  With this code I see the MdiChild size and position change along with the frame title.

I spent an hour or so downloading and trying to build with the latest Nevron UI for .Net build on the website.  I uninstalled the build I've been using and installed the new one.  I can get my code to build with it and it runs but I see the exact same symptoms using the latest build.  I doesn't work with this build either.  (I know I'm using the latest Nevron UI build now because I see the Evaluate popup now.)  I tried the following and this mostly works but has some issues still (like not affecting the top most frame title when the document is maximized):

if (doc.Host is NMdiChild)

{

NMdiChild child = doc.Host as NMdiChild;

child.Text = title;

}

Also, I also found another problem with little testing thus far on the latest build:  I register:

DockManager.DocumentManager.DocumentClosing += new DocumentCancelEventHandler(DocumentManager_DocumentClosing);

private void DocumentManager_DocumentClosing(object sender, DocumentCancelEventArgs e)

{

if (e.Document.Client == null)

return;

NForm frm = (NForm)e.Document.Client;

if (!frm.IsDisposed)

{

frm.Close();

if (!frm.IsDisposed)

{

e.Cancel = true;

}

}

}

I put NForms on my doc.Client.  The above cast to NForm will always work.  When doing this the frm.Close() above now causes a NullReferenceException in this designer code on my form on the base.Dispose() line:

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

This is a major regression as I rely on the frm.Close to know if it can't be closed at this time.  I don't believe I can move up to this build.  Any further advice on either issue?

By Nevron Support - 12 Years Ago
Hi Craig,

Could you send us an example app which demonstrates the relocating and resizing of the document when the Text was changed.

Regarding the second problem you described, this happens because when Close() is called this internally calls Dispose() which disposes the Palette and then calls Form.Dispose(). However Form.Dispose() gets internally overridden ForeColor and BackColor properties which on other hand takes their values from already disposed Palette property.

To avoid this you can use NUIPanel control instead of NForm.
By Craig Swearingen - 12 Years Ago

Thanks, I'll try to work on getting a test case which demonstrates the MdiChild window moving and resizing.

Regarding placing NForms as a client on a NUIDocument.  I need the ability to VS design and show an NForm in its own window, in a NUIDocument, or as a child control on an NDockingPanel.  The same NForm could be needed in any way.  This has been working fine for me in the last two Nevron UI licenses I've owned. 

(This document indicates in part how this can be done:  http://support.nevron.com/KB/a189/split-big-panel-application-without-losing-vs-design-support.aspx)

I've relied on this so changing to a NUIPanel isn't an option for me but I can see how this would fix the issue.  It could be I don't understand your suggestion, though.  I don't fully understand why this has stopped working on this event (due to the palette changes) since the last build I picked up at the beginning of the year but there should be a way to fix this in the Nevron code in a future build to not cause this exception, right?

 

By Nevron Support - 12 Years Ago
Hi Craig,

I understood the need of using NForm.
Using NUIPanel was just a suggestion of fixing the problem before we fix it in a service pack.

As soon as we release a service pack with the fix we will let you know.
By Craig Swearingen - 12 Years Ago
Thanks for that clarification.  I was able to narrow down the resize/reposition issue when setting the title.  Once you set the NUIDocument.PreferredBounds to something you'd like then this issue shows up.  Is there a way to work around this issue?  I've attached a sample program that reproduces the issue.
By Nevron Support - 12 Years Ago

Hello Craig,

When you set the Text property of NUIDocument, NMdiChild control where NUIDocument resides internally updates its properties from NUIDocument along with PreferredSize.

To avoid this, you can set PreferredSize to empty rectangle in btn_Click event handler from the attached example.

 

Just to mention, the problem with NullReferenceException is solved and the fix will be available with the next service pack.

By Craig Swearingen - 12 Years Ago
Thanks for the update on the NullReferenceException issue and the suggestion for the work around on the resize/reposition issue.  The work around works fine for me.