Profile Picture

Change menu font

Posted By Jan Dijkstra 13 Years Ago
Author
Message
Jan Dijkstra
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 3, Visits: 1

I have the following code:

public void SetMenuEnabled(bool isEnabled)
{
   foreach (NCommandContext context in (myCommandManager.Contexts))
   {
       if(context.Properties.Text == "test")
       {
           context.Properties.Selectable = isEnabled;
           context.Properties.Font = new Font(context.Properties.Font.Name, context.Properties.Font.Size, FontStyle.Bold);
       }
   }
}

myCommandManager is an NCommandBarsManager.
When I run this code I get an NullReferenceEception. And when I hover with the mouse, it says that .Font = null.
The setting of the Selectable property works all fine when I comment the .Font line...

How can I set the .Font property?

 



Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hello Jan,

NCommandContext.Properties.Font property by default is null, so I guess you didn't set it before.
You can check whether is null and if so, you can set it to the NCommandBarsManager.ParentControl.Font which should be the Form or other control that Command Bars Manager resides.

It may look similar to this:

int nCount = nCommandBarsManager1.Contexts.Count;

for (int i = 0; i < nCount; i++)
{
NCommandContext context = myCommandManager.Contexts[i];
context.Properties.Selectable = isEnabled;
Font contextFont = context.Properties.Font;
if (contextFont != null)
{
Font f = new Font(contextFont, FontStyle.Bold);
context.Properties.Font = f;
}
else
{
Font f = new Font(myCommandManager.ParentControl.Font, FontStyle.Bold);
}
}

I hope it helps.

Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic