2 Answers, 1 is accepted
Hello,
To customize the context menu and increase the font size, you should subscribe to the ContextMenuOpening event and apply desired font settings by setting the Font property.
Please refer to the following code snippet:
private void RadGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
e.ContextMenu.Font = new Font("Arial", 14, FontStyle.Regular);
}
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.
HI ~
i create a new project
and write codes as you suggest
private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
e.ContextMenu.Font = new Font("Arial", 20, FontStyle.Regular);
var cellElement = e.ContextMenuProvider as GridCellElement;
if (cellElement == null) return;
if (cellElement is GridHeaderCellElement)
{
RadMenuItem exportExcel = new RadMenuItem($"ExportToExcel");
exportExcel.Click += (s, args) => { ExportToExcel(); };
e.ContextMenu.Items.Add(exportExcel);
}
}
but the text size still small
i attach my proect writing VS2022
Hello,
Thank you for providing a sample project. I was able to observe the same behavior in the project. The different behavior came because in your project the Fluent theme is used.
Please refer to the following code snippet, which iterates the ContextMenu.Items collection and apply the custom Font to each item:
private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
var cellElement = e.ContextMenuProvider as GridCellElement;
if (cellElement == null) return;
if (cellElement is GridHeaderCellElement)
{
RadMenuItem exportExcel = new RadMenuItem($"ExportToExcel");
exportExcel.Click += (s, args) => { ExportToExcel(); };
e.ContextMenu.Items.Add(exportExcel);
}
foreach (RadItem item in e.ContextMenu.Items)
{
item.Font = new Font("Arial", 20, FontStyle.Regular);
}
}I hope this helps. If you have any other questions, do not hesitate to contact me again.
HI ~ as yuo suggest
problems solved ~ set each item's font and it's work
"The different behavior came because in your project the Fluent theme is used." as you mension
1. what's "the Fluent theme is used" ?
2. How can i solve this issue if i want to use "e.ContextMenu.Font = new Font("Arial", 20, FontStyle.Regular);" rathen then
foreach (RadItem item in e.ContextMenu.Items)
{
item.Font = new Font("Arial", 20, FontStyle.Regular);
}TKS ~
Hello,
I am glad to hear that the problem is now resolved.
As to your questions, the Fluent theme is one of the available themes that we support in the WinForms suite and also at this time being is the default one for our components: Default Theme. Here you can see the whole theme list. Every theme may differ in some aspects in its implementation compared to the others, and this may result in different settings applied to the component according to which theme is used. This does not happen for all visual elements, but for some of them. By providing different themes, we offer various looks and feels to our components, allowing our customers to choose the best look for their applications.
For example, if you use the ControlDefault theme (by setting RadGridView.ThemeName = "ControlDefault"), the code example setting "e.ContextMenu.Font = new Font("Arial", 20, FontStyle.Regular);" should work. However, it is absolutely fine when the Fluent theme is applied to specify the Font for each item. This is also a valid and possible solution to achieve the same behavior.
So, if you start work with the Fluent theme and prefer to continue working with it, is absolutely fine to use the code snippet that I suggested in my previous reply.
Regards,
Nadya
HI~
And how about the submenu ?
it also shown small
The approach here to target the submenu items will be similar. Here is what you can do:
private void RadGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
foreach (RadItem item in e.ContextMenu.Items)
{
var menuItem = item as RadMenuItem;
if (menuItem != null)
{
foreach (var subItem in menuItem.Items)
{
subItem.Font = new Font("Arial", 20, FontStyle.Regular);
}
}
item.Font = new Font("Arial", 20, FontStyle.Regular);
}
}
