473,890 Members | 1,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Q] OwnerDraw Menu - Large Font - MainMenuBar thickness

Dear Group,

I am new to c# and windows form designer - coming from a Motif
background.

I am attempting to develop an application for a touch screen and I
need to have a menu system with a larger font to allow ease of
selection.

I have used OwnerDraw menus implementing the DrawItemEventHa ndler and
MeasureItemEven tHandler event handlers.

My attached sample works for the menus, however the MainMenubar
thickness is still the default thickness.

How do I change the Main menu bar thickness? So I can use larger
fonts for my application.

Thanks

Stuart

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

namespace bigmenu
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.MainMenu mainMenu;
private System.Windows. Forms.MenuItem MenuMain;
private System.Windows. Forms.MenuItem MenuItemOne;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
this.mainMenu = new System.Windows. Forms.MainMenu( );
this.MenuMain = new System.Windows. Forms.MenuItem( );
this.MenuItemOn e = new System.Windows. Forms.MenuItem( );
//
// mainMenu
//
this.mainMenu.M enuItems.AddRan ge(new
System.Windows. Forms.MenuItem[] {this.MenuMain} );
//
// MenuMain
//
this.MenuMain.D efaultItem = true;
this.MenuMain.I ndex = 0;
this.MenuMain.M enuItems.AddRan ge(new
System.Windows. Forms.MenuItem[] {this.MenuItemO ne});
this.MenuMain.O wnerDraw = true;
this.MenuMain.T ext = "Menu One";
this.MenuMain.D rawItem += new
System.Windows. Forms.DrawItemE ventHandler(thi s.MenuItemDrawI tem);
this.MenuMain.M easureItem += new
System.Windows. Forms.MeasureIt emEventHandler( this.MenuItemMe asureItem);
//
// MenuItemOne
//
this.MenuItemOn e.Index = 0;
this.MenuItemOn e.OwnerDraw = true;
this.MenuItemOn e.Text = "MenuItem One";
this.MenuItemOn e.DrawItem += new
System.Windows. Forms.DrawItemE ventHandler(thi s.MenuItemDrawI tem);
this.MenuItemOn e.MeasureItem += new
System.Windows. Forms.MeasureIt emEventHandler( this.MenuItemMe asureItem);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Menu = this.mainMenu;
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void MenuItemMeasure Item (Object sender,
MeasureItemEven tArgs e)
{
MenuItem menuItem = (MenuItem) sender;
Font font = new System.Drawing. Font("Microsoft Sans Serif", 18.0F,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
// Determine the size menuItem in the new font.
SizeF stringSize = e.Graphics.Meas ureString(menuI tem.Text, font);
// Set the height and width of the item
e.ItemHeight = (int)stringSize .Height;
e.ItemWidth = (int)stringSize .Width;
}

private void MenuItemDrawIte m( Object sender, DrawItemEventAr gs e)
{
MenuItem menuItem = (MenuItem) sender;
System.Drawing. Brush brush = System.Drawing. Brushes.Black;
Font font = new System.Drawing. Font("Microsoft Sans Serif", 18.0F,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
SizeF stringSize = e.Graphics.Meas ureString(font. Name, font);
// Highlight the rectangle and the menu head if needed
if (( e.State & DrawItemState.S elected ) == DrawItemState.S elected)
e.Graphics.Fill Rectangle(Syste mBrushes.Highli ght,e.Bounds);
else
e.Graphics.Fill Rectangle(Syste mBrushes.Menu,e .Bounds);
// Finally Draw the string on the screen.
e.Graphics.Draw String(menuItem .Text, font,brush,e.Bo unds.X,
e.Bounds.Y);

}
}
}
Nov 16 '05 #1
2 2850
If you add your menu inside a ReBar control (like menus in internet explorer
or developer studio), then you can set the height of rebar control to
watever you want.

Shak.
"Stuart Norris" <st**********@y ahoo.com.au> wrote in message
news:51******** *************** ***@posting.goo gle.com...
Dear Group,

I am new to c# and windows form designer - coming from a Motif
background.

I am attempting to develop an application for a touch screen and I
need to have a menu system with a larger font to allow ease of
selection.

I have used OwnerDraw menus implementing the DrawItemEventHa ndler and
MeasureItemEven tHandler event handlers.

My attached sample works for the menus, however the MainMenubar
thickness is still the default thickness.

How do I change the Main menu bar thickness? So I can use larger
fonts for my application.

Thanks

Stuart

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

namespace bigmenu
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.MainMenu mainMenu;
private System.Windows. Forms.MenuItem MenuMain;
private System.Windows. Forms.MenuItem MenuItemOne;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
this.mainMenu = new System.Windows. Forms.MainMenu( );
this.MenuMain = new System.Windows. Forms.MenuItem( );
this.MenuItemOn e = new System.Windows. Forms.MenuItem( );
//
// mainMenu
//
this.mainMenu.M enuItems.AddRan ge(new
System.Windows. Forms.MenuItem[] {this.MenuMain} );
//
// MenuMain
//
this.MenuMain.D efaultItem = true;
this.MenuMain.I ndex = 0;
this.MenuMain.M enuItems.AddRan ge(new
System.Windows. Forms.MenuItem[] {this.MenuItemO ne});
this.MenuMain.O wnerDraw = true;
this.MenuMain.T ext = "Menu One";
this.MenuMain.D rawItem += new
System.Windows. Forms.DrawItemE ventHandler(thi s.MenuItemDrawI tem);
this.MenuMain.M easureItem += new
System.Windows. Forms.MeasureIt emEventHandler( this.MenuItemMe asureItem);
//
// MenuItemOne
//
this.MenuItemOn e.Index = 0;
this.MenuItemOn e.OwnerDraw = true;
this.MenuItemOn e.Text = "MenuItem One";
this.MenuItemOn e.DrawItem += new
System.Windows. Forms.DrawItemE ventHandler(thi s.MenuItemDrawI tem);
this.MenuItemOn e.MeasureItem += new
System.Windows. Forms.MeasureIt emEventHandler( this.MenuItemMe asureItem);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Menu = this.mainMenu;
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void MenuItemMeasure Item (Object sender,
MeasureItemEven tArgs e)
{
MenuItem menuItem = (MenuItem) sender;
Font font = new System.Drawing. Font("Microsoft Sans Serif", 18.0F,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
// Determine the size menuItem in the new font.
SizeF stringSize = e.Graphics.Meas ureString(menuI tem.Text, font);
// Set the height and width of the item
e.ItemHeight = (int)stringSize .Height;
e.ItemWidth = (int)stringSize .Width;
}

private void MenuItemDrawIte m( Object sender, DrawItemEventAr gs e)
{
MenuItem menuItem = (MenuItem) sender;
System.Drawing. Brush brush = System.Drawing. Brushes.Black;
Font font = new System.Drawing. Font("Microsoft Sans Serif", 18.0F,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
SizeF stringSize = e.Graphics.Meas ureString(font. Name, font);
// Highlight the rectangle and the menu head if needed
if (( e.State & DrawItemState.S elected ) == DrawItemState.S elected)
e.Graphics.Fill Rectangle(Syste mBrushes.Highli ght,e.Bounds);
else
e.Graphics.Fill Rectangle(Syste mBrushes.Menu,e .Bounds);
// Finally Draw the string on the screen.
e.Graphics.Draw String(menuItem .Text, font,brush,e.Bo unds.X,
e.Bounds.Y);

}
}
}

Nov 16 '05 #2
Hi All,

Just a quick followup on this.

Is the only way to change the height of the main menubar using a third
party package.

How do they do it? Do they draw the menus completely differently.

Thanks

Stuie
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2349
by: Rob Mayo | last post by:
How can I force a MeasureItem message for an owner-dramn menu item? Here is the dilemma. I wrote a lovely little Component for owner-drawing all the menus on a form and making them look like Office XP-style menus (mostly an academic exercise). I came across a problem with another app I wrote, which is using this Component. The app changes the text in the menu items depending on what is selected in the app. The fisrt time the menu may be...
2
3322
by: Jacques | last post by:
Hello, I am creating a menu for an Office Add-in. The menu displays OK. But, each time I run the Office App (Word) it adds another menu item. The Word menu bar looks like: File | Edit | View |.. | My Menu | My Menu | My Menu |..
0
1106
by: Apollo440 | last post by:
If MenuItem.OwnerDraw Property is true,.NET framework does not recognize the overlapped accelerator keys. Is there a workaround? eg) +------+ |&Test | <- |&Tea | <- MenuItems has overlapped accelerator keys "T" & OwnerDraw = true
2
1744
by: jm | last post by:
There are properties for OwnerDraw on ContextMenu items. I know it can be done with regular menus. I cannot find anyone doing it with the systray icon contextmenu (notifyicon.) Is it possible to change fonts, colors, etc. of a context menu item if it is a system tray contextmenu? Thank you.
0
999
by: Michel | last post by:
I come back with a new question regarding my OwnerDraw menu. That is a classical ownerDraw menu to add icon and some other color properties. My feature is to color all the menu bar with the background color of the items. So I feel the left side of the menu bar with a FillRectangle. I gather the width of the form for the Rectangle definition Everything works well.
2
1275
by: Peter Proost | last post by:
Hi group, I've got this ownerdraw menu module which I got from a site and modified to my personal needs, but the only problem I'm having is with the lines in a menu, when you type - as text, it normaly becomes a full line and the height of the menuitem is reduced but when you set a menu to ownerdraw and use my draw and measure item handlers this doesn't work anymore, has anyone worked out a good sloution for this before? Greetz Peter
2
1349
by: Peter Proost | last post by:
Hi, I've got the following ownerdraw menu: drag a mainmenu on a form and add some menuitems to it, set all the menuitems to ownerdraw = true and for every menuitem add this code (replace nothing with an ico if you want to show an icon in the menu) also add a module and copy paste the code at the bottom of the message. Private Sub MenuItem1_DrawItem1(ByVal sender As Object, ByVal e As _
0
1052
by: genojoe | last post by:
This code is derived from: ms-help://MS.VSCC.2003/MS.MSDNQTR.2005JUL.1033/cpref/html/frlrfSystemWindowsFormsMenuItemClassOwnerDrawTopic.htm The sample works as presented but does not contain a click event. Here is my abridged version of the code. In this code, if I use MenuItem2.OwnerDraw = False, it behaves as expected: no ownerdraw and when clicked, I see the message. If MenuItem2.OwnerDraw = True, I see the colored text but when...
2
4625
by: cbjewelz | last post by:
Hey. I'm creating a horizontal boxed CSS menu for my site using lists. I wish to achieve a main menu bar something like this: http://kurafire.net/log/ however when I add borders to my code it adds the borders of each li so I get double thickness borders. I only want 1px so its a problem. here is my code: <style> #underlinemenu{ margin: 0; padding: 0;
0
9821
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11229
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9630
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8016
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6042
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3276
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.