|
|
|
date: Sun, 29 Jun 2008 16:11:08 -0600,
group: microsoft.public.dotnet.framework.windowsforms.controls
back
RE: popup menu - smaller?
Hi David,
I suggest that you use the ToolStripRenderer to customize the appearance of
the ContextMenuStrip,e.g. minimize the height of the items in the
ContextMenuStrip so as to make the ContextMenuStrip look smaller.
The following is a sample:
class MyToolStripRenderer : ToolStripProfessionalRenderer
{
int maxwidth = 0;
int itemheight = 16;
protected override void Initialize(ToolStrip toolStrip)
{
base.Initialize(toolStrip);
ToolStripDropDownMenu menu = toolStrip as
ToolStripDropDownMenu;
if (menu != null)
{
menu.ShowCheckMargin = false;
menu.ShowImageMargin = false;
}
foreach (ToolStripItem item in toolStrip.Items)
{
Size size = TextRenderer.MeasureText(item.Text,
item.Font);
maxwidth = Math.Max(maxwidth, size.Width);
}
maxwidth += toolStrip.GripMargin.Left +
toolStrip.Padding.Left ;
toolStrip.AutoSize = false;
toolStrip.Width = maxwidth;
toolStrip.Height = itemheight * toolStrip.Items.Count + 4;
}
protected override void InitializeItem(ToolStripItem item)
{
base.InitializeItem(item);
item.AutoSize = false;
item.Height = itemheight;
item.Width = maxwidth;
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.contextMenuStrip1.Renderer = new MyToolStripRenderer();
}
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
date: Mon, 30 Jun 2008 08:49:17 GMT
author: (Linda Liu[MSFT])
Re: popup menu - smaller?
Hi;
This menu is not in a toolstrip - it is a pop-up menu like what you
get for a context menu when you do a RMB click with the mouse. So all
we have is a menu but no ContextMenuStrip.
Am I not understanding how this can be used? Is there a way to do this
where the menu strip is invisible or doesn't exist?
thanks - dave
On Mon, 30 Jun 2008 08:49:17 GMT, v-lliu@online.microsoft.com (Linda
Liu[MSFT]) wrote:
>Hi David,
>
>I suggest that you use the ToolStripRenderer to customize the appearance of
>the ContextMenuStrip,e.g. minimize the height of the items in the
>ContextMenuStrip so as to make the ContextMenuStrip look smaller.
>
>The following is a sample:
>
>class MyToolStripRenderer : ToolStripProfessionalRenderer
> {
> int maxwidth = 0;
> int itemheight = 16;
> protected override void Initialize(ToolStrip toolStrip)
> {
> base.Initialize(toolStrip);
> ToolStripDropDownMenu menu = toolStrip as
>ToolStripDropDownMenu;
> if (menu != null)
> {
> menu.ShowCheckMargin = false;
> menu.ShowImageMargin = false;
> }
> foreach (ToolStripItem item in toolStrip.Items)
> {
> Size size = TextRenderer.MeasureText(item.Text,
>item.Font);
> maxwidth = Math.Max(maxwidth, size.Width);
> }
> maxwidth += toolStrip.GripMargin.Left +
>toolStrip.Padding.Left ;
>
> toolStrip.AutoSize = false;
> toolStrip.Width = maxwidth;
> toolStrip.Height = itemheight * toolStrip.Items.Count + 4;
> }
>
> protected override void InitializeItem(ToolStripItem item)
> {
> base.InitializeItem(item);
> item.AutoSize = false;
> item.Height = itemheight;
> item.Width = maxwidth;
> }
>}
>
>private void Form1_Load(object sender, EventArgs e)
> {
> this.contextMenuStrip1.Renderer = new MyToolStripRenderer();
>}
>
>Hope this helps.
>If you have any question, please feel free to let me know.
>
>Sincerely,
>Linda Liu
>Microsoft Online Community Support
>
>Delighting our customers is our #1 priority. We welcome your comments and
>suggestions about how we can improve the support we provide to you. Please
>feel free to let my manager know what you think of the level of service
>provided. You can send feedback directly to my manager at:
>msdnmg@microsoft.com.
>
>==================================================
>Get notification to my posts through email? Please refer to
>http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>ications.
>
>Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
>where an initial response from the community or a Microsoft Support
>Engineer within 1 business day is acceptable. Please note that each follow
>up response may take approximately 2 business days as the support
>professional working with you may need further investigation to reach the
>most efficient resolution. The offering is not appropriate for situations
>that require urgent, real-time or phone-based interactions or complex
>project analysis and dump analysis issues. Issues of this nature are best
>handled working with a dedicated Microsoft Support Engineer by contacting
>Microsoft Customer Support Services (CSS) at
>http://msdn.microsoft.com/subscriptions/support/default.aspx.
>==================================================
>This posting is provided "AS IS" with no warranties, and confers no rights.
david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm
date: Mon, 30 Jun 2008 10:24:04 -0600
author: David Thielen am
Re: popup menu - smaller?
Hi David,
Thank you for your quick reply!
In your first message, you said "I have a ContextMenuStrip that pops up and
works fine. However, Iwould like for it to be smaller...".
In .NET 2.0, the method to customize the appearance of a ToolStrip, a
MenuStrip or a ContextMenuStrip is to implement a custom ToolStripRenderer.
The sample I provided in my first reply requires that you add a
ContextMenuStrip named contextMenuStrip1 on a form and paste the sample
code into the form's code file.
For more information about the ToolStripRenderer class, see the following
document:
"ToolStripRenderer Class"
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstriprender
er.aspx
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
date: Tue, 01 Jul 2008 09:25:24 GMT
author: (Linda Liu[MSFT])
Re: popup menu - smaller?
Hi;
Ok, that makes sense. I have your code working. One weird thing
though, it pushes the text of the menu item down so there is space
above the text for each item but the bottom of it is cropped off.
Any idea how to fix that?
thanks - dave
On Tue, 01 Jul 2008 09:25:24 GMT, v-lliu@online.microsoft.com (Linda
Liu[MSFT]) wrote:
>Hi David,
>
>Thank you for your quick reply!
>
>In your first message, you said "I have a ContextMenuStrip that pops up and
>works fine. However, Iwould like for it to be smaller...".
>
>In .NET 2.0, the method to customize the appearance of a ToolStrip, a
>MenuStrip or a ContextMenuStrip is to implement a custom ToolStripRenderer.
>
>The sample I provided in my first reply requires that you add a
>ContextMenuStrip named contextMenuStrip1 on a form and paste the sample
>code into the form's code file.
>
>For more information about the ToolStripRenderer class, see the following
>document:
>"ToolStripRenderer Class"
>http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstriprender
>er.aspx
>
>If you have any question, please feel free to let me know.
>
>Sincerely,
>Linda Liu
>Microsoft Online Community Support
>
>Delighting our customers is our #1 priority. We welcome your comments and
>suggestions about how we can improve the support we provide to you. Please
>feel free to let my manager know what you think of the level of service
>provided. You can send feedback directly to my manager at:
>msdnmg@microsoft.com.
>
>This posting is provided "AS IS" with no warranties, and confers no rights.
david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm
date: Tue, 01 Jul 2008 17:10:54 -0600
author: David Thielen am
Re: popup menu - smaller?
ps - I added the line:
toolStrip.Font = new Font(toolStrip.Font.FontFamily, 9);
On Tue, 01 Jul 2008 17:10:54 -0600, David Thielen
<thielen@nospam.nospam> wrote:
>Hi;
>
>Ok, that makes sense. I have your code working. One weird thing
>though, it pushes the text of the menu item down so there is space
>above the text for each item but the bottom of it is cropped off.
>
>Any idea how to fix that?
>
>thanks - dave
>
>
>On Tue, 01 Jul 2008 09:25:24 GMT, v-lliu@online.microsoft.com (Linda
>Liu[MSFT]) wrote:
>
>>Hi David,
>>
>>Thank you for your quick reply!
>>
>>In your first message, you said "I have a ContextMenuStrip that pops up and
>>works fine. However, Iwould like for it to be smaller...".
>>
>>In .NET 2.0, the method to customize the appearance of a ToolStrip, a
>>MenuStrip or a ContextMenuStrip is to implement a custom ToolStripRenderer.
>>
>>The sample I provided in my first reply requires that you add a
>>ContextMenuStrip named contextMenuStrip1 on a form and paste the sample
>>code into the form's code file.
>>
>>For more information about the ToolStripRenderer class, see the following
>>document:
>>"ToolStripRenderer Class"
>>http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstriprender
>>er.aspx
>>
>>If you have any question, please feel free to let me know.
>>
>>Sincerely,
>>Linda Liu
>>Microsoft Online Community Support
>>
>>Delighting our customers is our #1 priority. We welcome your comments and
>>suggestions about how we can improve the support we provide to you. Please
>>feel free to let my manager know what you think of the level of service
>>provided. You can send feedback directly to my manager at:
>>msdnmg@microsoft.com.
>>
>>This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>david@at-at-at@windward.dot.dot.net
>Windward Reports -- http://www.WindwardReports.com
>me -- http://dave.thielen.com
>
>Cubicle Wars - http://www.windwardreports.com/film.htm
david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm
date: Tue, 01 Jul 2008 17:16:59 -0600
author: David Thielen am
Re: popup menu - smaller?
Hi David,
Thank you for your reply!
> One weird thing though, it pushes the text of the menu item down so there
is space above the text for each item but the bottom of it is cropped off.
Yes, it is. I do more research and find the solution, i.e, override the
OnRenderItemText method in the derived ToolStripProfessionalRenderer class.
The following is a sample:
class MyToolStripRenderer : ToolStripProfessionalRenderer
{
....
protected override void
OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
if (e.TextColor == SystemColors.HighlightText)
{ e.TextColor = e.Item.ForeColor; }
e.Graphics.DrawString(e.Text, e.Item.Font, new
SolidBrush(e.TextColor),0,-3);
}
}
It works fine on my side. Please try it in your application to see if
there's any problem.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
date: Wed, 02 Jul 2008 08:34:13 GMT
author: (Linda Liu[MSFT])
Re: popup menu - smaller?
that did it - thanks - dave
ps - it would be nice if they had a simple "tool bar menu" control.
On Wed, 02 Jul 2008 08:34:13 GMT, v-lliu@online.microsoft.com (Linda
Liu[MSFT]) wrote:
>Hi David,
>
>Thank you for your reply!
>
>> One weird thing though, it pushes the text of the menu item down so there
>is space above the text for each item but the bottom of it is cropped off.
>
>Yes, it is. I do more research and find the solution, i.e, override the
>OnRenderItemText method in the derived ToolStripProfessionalRenderer class.
>The following is a sample:
>
>class MyToolStripRenderer : ToolStripProfessionalRenderer
>{
> ....
> protected override void
>OnRenderItemText(ToolStripItemTextRenderEventArgs e)
> {
> if (e.TextColor == SystemColors.HighlightText)
> { e.TextColor = e.Item.ForeColor; }
>
> e.Graphics.DrawString(e.Text, e.Item.Font, new
>SolidBrush(e.TextColor),0,-3);
> }
>}
>
>It works fine on my side. Please try it in your application to see if
>there's any problem.
>
>Sincerely,
>Linda Liu
>Microsoft Online Community Support
>
>Delighting our customers is our #1 priority. We welcome your comments and
>suggestions about how we can improve the support we provide to you. Please
>feel free to let my manager know what you think of the level of service
>provided. You can send feedback directly to my manager at:
>msdnmg@microsoft.com.
>
>This posting is provided "AS IS" with no warranties, and confers no rights.
>
david@at-at-at@windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com
Cubicle Wars - http://www.windwardreports.com/film.htm
date: Tue, 15 Jul 2008 17:46:11 -0600
author: David Thielen am
|
|