.NET Framework - Button with arrowdown (acting as a combobox)
Asked By Soeren D.
22-Jun-07 08:28 AM
I have seen WinForm applications with a control, that I am pretty sure is
standard in .NET 2.0
It is a button with a leftadjusted text followed by an arrow pointing down.
When the button is pressed, a menu is shown benieth and the text of the
selected menuitem becomes the new buttontext.
From a functional point of view it is a combobox, but this design is
wellsuited for my application.
Do you know where to find it?
Thanks in advance.
Best regards
Soeren
System.Windows.Forms.PaintEventArgs
(1)
SystemBrushes.ControlText
(1)
ToolStripDropDownButton
(1)
SystemBrushes
(1)
MeasureString
(1)
DrawString
(1)
Component
(1)
Button
(1)
Kevin Spencer replied...
There is a ToolStripDropDownButton class that does this.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
Soeren D. replied...
Hi Kevin,
I tried to look it up but is appears to be for toolstrips only and I would
like to use it in the form itself.
But thanks for the tip.
Best regards
Soeren
Kevin Spencer replied...
In that case, create a button that has an arrow on it, and put it next to
another button.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
Jeff Johnson replied...

A while back I needed a "More/Less" button which expanded or collapsed a
form, and I wanted a nice up/down arrow for it as opposed to the more common
like this:
private void MoreInfoButton_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
Font f = new Font("Marlett", MoreInfoButton.Font.Size * 1.1f);
string Arrow;
float TextWidth;
if (_expanded)
Arrow = "5";
else
Arrow = "6";
TextWidth = g.MeasureString(MoreInfoButton.Text,
MoreInfoButton.Font).Width;
g.DrawString(Arrow, f, SystemBrushes.ControlText, TextWidth - 6,
(e.ClipRectangle.Height - g.MeasureString(Arrow, f).Height) / 2);
}
There's some "fudge factor" numbers going on there which were necessary (if
I remember right) because Graphics.MeasureString() wasn't returning a 100%
correct result. However, this was written in .NET 1.1 and maybe this has
changed in 2.0.
As for the dropdown, you could simply create a ContextMenu[Strip] and
display it directly below your button when clicked.
Doing a simple gradient background on a form: Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) Dim r As Rectangle = ClientRectangle Dim b As Brush = New System.Drawing not re-drawing the form? Thanks, kpg VB.NET Discussions System.Drawing.Drawing2D.LinearGradientBrush (1) System.Windows.Forms.PaintEventArgs (1) ControlStyles.ResizeRedraw (1) LinearGradientBrush (1) LinearGradientMode (1) MyBase.OnPaint (1) System.EventArgs (1) EventArgs
transparent image as a watermark on a multiline textbox? TIA, Johnny J. VB.NET Discussions System.Windows.Forms.PaintEventArgs (1) System.Windows.Forms.Textbox (1) ControlStyles.UserPaint (1) TextRenderer.DrawText (1) Windows.Forms.Textbox True SetStyle(ControlStyles.UserPaint, True) End Sub Protected Overrides Sub OnPaint _ (ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) If (Image IsNot Nothing) Then e.Graphics.DrawImage(Image, New PointF(0
Ich habe mit TransformRotate usw. experimentiert aber nicht hinbekommen. Danke! Frank VB.NET - German Discussions System.Windows.Forms.PaintEventArgs (1) TranslateTransform (1) ScaleTransform (1) Pens.Black (1) DrawLine (1) Control (1) Pens (1) Control Single Return control.ClientSize.Height - ordinate End Function Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) 'MyBase.OnPaint(e) e.Graphics.DrawLine(Pens.Black, 10, Screen2World(Me, 10), 100, Screen2World(Me
label text within VB .NET 2003? I'd appreciate the tip. Thanks. VB.NET Discussions System.Windows.Forms.PaintEventArgs (1) System.Windows.Forms.UserControl (1) System.Windows.Forms.Control (1) System.ComponentModel.Container (1 New System.Drawing.Size(24, 100) End Sub Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) Dim sngControlWidth As Single Dim sngControlHeight As Single Dim sngTransformX As Single Dim sngTransformY As