Click here to Skip to main content
Licence 
First Posted 13 Sep 2005
Views 102,981
Bookmarked 85 times

Custom Arrow Button

By | 13 Sep 2005 | Article
A button that looks like an arrow.

Testform with several ArrowButtons

Introduction

In an earlier VC++ (MFC) project, I designed a GUI with which the assistance robots in a machine could be positioned. For that I changed the rectangular button shape into an arrow shape. I have taken up the idea to program such arrows also in C# (.NET Framework). For that I read the most, very helpful, article about shaped forms on CodeProject. So with that information and the goal to deepen my knowledge in C# (GDI+, .NET Framework), I started the project. Here is the result.

Using the code

The project is designed as a custom control. In my article "PictureBox with zooming and scrolling", I described how to install and use such a control, or have a look at the different articles about that topic in CodeProject, for example "Writing your Custom Control: step by step" by Alexandr Khilov.

Methods / Properties

The control provides six designer related properties:

Designer properties

  • NormalStartColor, NormalEndColor -> Start- and End color for the LinearGradientBrush in normal state.
  • HoverStartColor, HoverEndColor -> Start- and End color for the LinearGradientBrush if the mouse cursor is over the arrow.
  • Rotation -> The pointing direction of the arrow in degrees. Starting with 0° at 12 O' clock raising clockwise to 360°.
  • ArrowEnabled -> Enable or disable the button. Act like the enable/disable in other controls.

Events

There is one public event in the class OnClickEvent. The event is fired if the mouse button is over the arrow and pressed.

Helper classes

The class BitArray is a simple helper class that I used to hold different button states (and to play a little bit with indexer). In the code you can see how to work with it.

ArrowButtonDesigner is derived from System.Windows.Forms.Design.ControlDesigner. A base designer class for extending the design mode behavior of a control. I used it only to hide properties.

A suggestion about the demo

Apart from the buttons -X and +X the other buttons have no function. If you click the x-value lower than 0 or make it bigger than 50, the HoverColor of the special ArrowButton will change to red.

Known restrictions

  • If you make the arrow too big, sometimes the calculation to prevent clipping doesn't work correct.
  • There is no test to check if the button text is correct in length and size.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Alexander Kloep

Software Developer
www.auteq.com
Germany Germany

Member

Working as software engineer since 2001 at www.auteq.com.
 
In my spare time i love playing with my two kids.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmemberpcs04144:07 5 Nov '11  
GeneralLike your Control [modified] Pinmemberthlorenz9:48 13 Jul '09  
AnswerRe: Like your Control PinmemberAlexander Kloep20:11 13 Jul '09  
QuestionCan I use Arrow Drawing Code in my App? PinmemberSukhjinder_K17:21 8 Nov '07  
GeneralGood control PinmemberBill Seddon1:21 7 Jan '07  
GeneralChange control shape from square to an arrow Pinmemberandrea@gmi3:37 20 Sep '06  
GeneralRe: Change control shape from square to an arrow PinmemberAlexander Kloep21:06 1 Oct '06  
GeneralBitArray Indexer Pinmembersmason58:43 2 Nov '05  
GeneralRe: BitArray Indexer PinmemberAlexander Kloep18:57 2 Nov '05  
GeneralIn an earlier VC++ (MFC) project... PinmemberKacee Giger8:15 14 Sep '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 13 Sep 2005
Article Copyright 2005 by Alexander Kloep
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid