By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

[Q] OwnerDraw Menu - Large Font - MainMenuBar thickness

P: n/a
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 DrawItemEventHandler and
MeasureItemEventHandler 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.Collections;
using System.ComponentModel;
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.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

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

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu = new System.Windows.Forms.MainMenu();
this.MenuMain = new System.Windows.Forms.MenuItem();
this.MenuItemOne = new System.Windows.Forms.MenuItem();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {this.MenuMain});
//
// MenuMain
//
this.MenuMain.DefaultItem = true;
this.MenuMain.Index = 0;
this.MenuMain.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {this.MenuItemOne});
this.MenuMain.OwnerDraw = true;
this.MenuMain.Text = "Menu One";
this.MenuMain.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.Men uItemDrawItem);
this.MenuMain.MeasureItem += new
System.Windows.Forms.MeasureItemEventHandler(this. MenuItemMeasureItem);
//
// MenuItemOne
//
this.MenuItemOne.Index = 0;
this.MenuItemOne.OwnerDraw = true;
this.MenuItemOne.Text = "MenuItem One";
this.MenuItemOne.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.Men uItemDrawItem);
this.MenuItemOne.MeasureItem += new
System.Windows.Forms.MeasureItemEventHandler(this. MenuItemMeasureItem);
//
// Form1
//
this.AutoScaleBaseSize = 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 MenuItemMeasureItem (Object sender,
MeasureItemEventArgs e)
{
MenuItem menuItem = (MenuItem) sender;
Font font = new System.Drawing.Font("Microsoft Sans Serif", 18.0F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
// Determine the size menuItem in the new font.
SizeF stringSize = e.Graphics.MeasureString(menuItem.Text, font);
// Set the height and width of the item
e.ItemHeight = (int)stringSize.Height;
e.ItemWidth = (int)stringSize.Width;
}

private void MenuItemDrawItem( Object sender, DrawItemEventArgs 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.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
SizeF stringSize = e.Graphics.MeasureString(font.Name, font);
// Highlight the rectangle and the menu head if needed
if (( e.State & DrawItemState.Selected ) == DrawItemState.Selected)
e.Graphics.FillRectangle(SystemBrushes.Highlight,e .Bounds);
else
e.Graphics.FillRectangle(SystemBrushes.Menu,e.Boun ds);
// Finally Draw the string on the screen.
e.Graphics.DrawString(menuItem.Text, font,brush,e.Bounds.X,
e.Bounds.Y);

}
}
}
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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**********@yahoo.com.au> wrote in message
news:51**************************@posting.google.c om...
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 DrawItemEventHandler and
MeasureItemEventHandler 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.Collections;
using System.ComponentModel;
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.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

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

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu = new System.Windows.Forms.MainMenu();
this.MenuMain = new System.Windows.Forms.MenuItem();
this.MenuItemOne = new System.Windows.Forms.MenuItem();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {this.MenuMain});
//
// MenuMain
//
this.MenuMain.DefaultItem = true;
this.MenuMain.Index = 0;
this.MenuMain.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {this.MenuItemOne});
this.MenuMain.OwnerDraw = true;
this.MenuMain.Text = "Menu One";
this.MenuMain.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.Men uItemDrawItem);
this.MenuMain.MeasureItem += new
System.Windows.Forms.MeasureItemEventHandler(this. MenuItemMeasureItem);
//
// MenuItemOne
//
this.MenuItemOne.Index = 0;
this.MenuItemOne.OwnerDraw = true;
this.MenuItemOne.Text = "MenuItem One";
this.MenuItemOne.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.Men uItemDrawItem);
this.MenuItemOne.MeasureItem += new
System.Windows.Forms.MeasureItemEventHandler(this. MenuItemMeasureItem);
//
// Form1
//
this.AutoScaleBaseSize = 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 MenuItemMeasureItem (Object sender,
MeasureItemEventArgs e)
{
MenuItem menuItem = (MenuItem) sender;
Font font = new System.Drawing.Font("Microsoft Sans Serif", 18.0F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
// Determine the size menuItem in the new font.
SizeF stringSize = e.Graphics.MeasureString(menuItem.Text, font);
// Set the height and width of the item
e.ItemHeight = (int)stringSize.Height;
e.ItemWidth = (int)stringSize.Width;
}

private void MenuItemDrawItem( Object sender, DrawItemEventArgs 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.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
SizeF stringSize = e.Graphics.MeasureString(font.Name, font);
// Highlight the rectangle and the menu head if needed
if (( e.State & DrawItemState.Selected ) == DrawItemState.Selected)
e.Graphics.FillRectangle(SystemBrushes.Highlight,e .Bounds);
else
e.Graphics.FillRectangle(SystemBrushes.Menu,e.Boun ds);
// Finally Draw the string on the screen.
e.Graphics.DrawString(menuItem.Text, font,brush,e.Bounds.X,
e.Bounds.Y);

}
}
}

Nov 16 '05 #2

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.