I'm try to get each ribbon tab on child form when its loaded to set the first tab (index 0) so the user would see this tab as the selected tab.
I read the following blog and tried it in VB.net:
>>> Ultratoolbarsmanager: How to programmatically activating a child tab
Here's my code:
==========================================================================
If Not activeChildManager Is Nothing Then
Dim parentTab As RibbonTab = childTab.AttachedParentTab
If Not parentTab Is Nothing Then
Else
End If
========================================================
But, [activeChildManager] is "Nothing" when I run the code
Note: the above code is located in the parent MDI form "MdiChildActivate" event.
Is the the correct location? (this is where I would like to manage all forms that load)
Have we missed something?
Thanks ahead of time.
Patrick
This is not the recommended location to sync up after an mdi child has been merged. The problem is, hooking this event is the only way the toolbars manager can determine when to merge with the newly active child, and if the toolbars manager happens to hook the event after your code does, your event handler of MdiChildActivate will likely get called before the toolbars manager's event handler. You would be called before the merge, and it looks like that's what's happening here.
It is instead recommended that you override OnMdiChildActivate in the parent form. Your implementation should call the base implementation first (this will call all event handlers, including the one on the toolbars manager which performs the merge), then it should select the first child tab.
Thanks Mike, but I could use more data. Where should I try this?
Any examples I could look at?
Thanks again,
I managed to make the following C# code in the MDI parent work perfectly. This kind of thing should be in the Infragistics KBase using the keyword "Merge" under UltraWinToolbar. Actually, what would be 100% better is an "AfterMdiChildMerge" event on the toolbar. Overriding a protected Form method is no big deal but to me this shouldn't be done through polymophism so much as event handling.
protected override void OnMdiChildActivate(EventArgs e) { base.OnMdiChildActivate(e); UltraToolbarsManager childToolbarsManager = this.UltraToolbarsManager.ActiveMdiChildManager; if (childToolbarsManager != null) { foreach (RibbonTab ribbonTab in childToolbarsManager.Ribbon.Tabs) { if (ribbonTab.AttachedParentTab != null) { this.UltraToolbarsManager.Ribbon.SelectedTab = ribbonTab.AttachedParentTab; break; } } } }
I can see that this post is ancient history, I can only hope that someone will see. Using code very similar to the above (exact code shown below) I am getting a NullReferenceException. The exception arises when switching from an MDI child to another instance of the same form as an MDI child (IE, I have two 'Client' forms open that are showing different clients). This works well if I switch from one open client to another MDI child that doesn't have a toolbar manager on it, and then switch to the other client. But when switching from one client to another, the exception arises.
Protected Overrides Sub OnMdiChildActivate(e As EventArgs) MyBase.OnMdiChildActivate(e) 'Exception comes here
If Me.tbrMain.ActiveMdiChildManager IsNot Nothing Then Me.tbrMain.Ribbon.SelectedTab = Me.tbrMain.ActiveMdiChildManager.Ribbon.Tabs(0).AttachedParentTab End If End Sub
Exception is NullReferenceException with the below stack trace.
at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.InternalSetActiveMdiChildManager(UltraToolbarsManager newActiveMdiChildManager, Boolean calledFromMdiChildActivate, Boolean remergeIfUnchanged) at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.OnFormMdiChildActivated(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Form.OnMdiChildActivate(EventArgs e) at ServTrue.frmMain.OnMdiChildActivate(EventArgs e) in D:\Development\Users\Matt\ServTrue\Trunk\ServTrue_Dev\Forms\General\frmMain.vb:line 2768 at System.Windows.Forms.Form.ActivateMdiChildInternal(Form form) at System.Windows.Forms.Form.WmMdiActivate(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Thanks in advance, let me know if I can provide more detailed information.
~Matt
Hello Matt,
Offhand I don't see anything within your code that would cause this exception to occur. It seems like the exception is happening once it goes into the base OnMdiChildActivate() call. Does the problem still occur if you comment out your override of the OnMdiChildActivate()?
I looked through our InternalSetActiveMdiChildManager() method, and nothing obvious jumps out to me in regards to a NullReferenceException being thrown. Additionally, I attempted to reproduce the problem, but was unsuccessful. My guess is there is something specific to the setup of your application that triggers the issue. I've attached my sample to this post. When you have the opportunity, see if you can reproduce the exception with my sample. Please make any changes necessary to the sample to match your application that will help in the reproduction of the problem.
Hopefully we can find a resolution for you quickly.
Chris
Well Chris, I pulled down your sample and copied over my exact toolbar setups and was not able to reproduce. I've clearly got something happening somewhere else in the code. I'll keep poking at it. Thanks for your help.
Hi Matt,
If you narrow down the cause of the issue with your application, please let me know. Hopefully we can add a fix for this scenario within our controls to avoid this issue in the future.
Additionally, if you have any other questions, feel free to ask.
Thanks,
Thanks for everything Chris. Your help is a testament to the level of customer care that we've come to expect from Infragistics.
Hey Matt.
I am the primary engineer for our toolbars suite, so of course I'll look deeper into the issue with the SelectedTab being different than the tab provided within the EventArgs.
In regards to the FontSize question, normally, we restrict the font size for all tools to be the same within the same parent. However, for the Ribbon, a single font size is enforced across the entire Ribbon. All tool/RibbonGroup related FontSize properties will be ignored. You would have to change the Ribbon's GroupSettings.ToolAppearance.FontData.FontSize for it to take affect. However, this will affect all tools on the Ribbon. If you are looking to only change the FontSize for this one tool, you'll most likely have to switch from using a TextBoxTool to using a ControlContainerTool and assigning an UltraTextEditor as the Control.
I hope this helps.
Thanks Chris, you've been a tremendous help. Not to be greedy with your time, but while I've got you, a couple of things:
1) By way of completeness, I wanted you to see that the toolbar's selected tab and the tab that is sent in AfterRibbonTabSelected are different any time the selected tab is changed in code. This is evidenced in the attached sample project. Might want to have an engineer look that over.
2) How ON EARTH do I get the font size to change on a TextBoxTool on the ribbon? On the Search tab in the attached project, I've got a text box tool that I am dying to have Comic Sans at 24 points. The InstanceProperties.EditAppearance seems to have allowed me to modify the font family, but not the size. Help?
Glad to hear that you got it working. I'm guessing it is the recursion that causes the ribbon's SelectedTab to be changed again after it fires the AfterRibbonTabSelected for the e.Tab.
Let me know if you need and further assistance.
Hey Chris, I was able to get this sorted. Definitely some oddness here because in the AfterRibbonTabSelected event, the ToolbarsManager.Ribbon.SelectedTab is NOT THE SAME as e.Tab. Anyway, managed to get around this using the below code.
Private Sub tbrMain_AfterRibbonTabSelected(sender As Object, e As Infragistics.Win.UltraWinToolbars.RibbonTabEventArgs) Handles tbrMain.AfterRibbonTabSelected If Not (e.Tab.Key.ToUpper.Contains("HOME") And (Me.tbrMain.Ribbon.SelectedTab IsNot Nothing AndAlso Me.tbrMain.Ribbon.SelectedTab.Key.ToUpper.Contains("MDICHILD"))) Then Me.FiddleWithActiveWindowsBasedOnTabSelection(e.Tab) End If End Sub