Resource to add a graphics-based random animated wheel to any form.
Spin the wheel, select the winner.
This plugin was created for use with the Picket application. However, I decided to extend the usage and provide a detailed interface with multiple options. This wheel can be customized and used with any Control. Please remember to give credit if using my code within your applications.
Four simple steps.
- Create the wheel object.
- Add Entries to the list.
- Draw the wheel.
- Spin the wheel.
This example form shows nearly all options available in the interface.
When initializing the Wheel, any control can be used as the Parent.
// Link the wheel to a form. IRandomTool wheel = new Wheel(this); // Or link the wheel to a control. IRandomTool wheel = new Wheel(label1);
// Use the Top Left Location and Radius. wheel.Draw(LocationX, LocationY, Radius); // Or use the Circle's center and Radius. wheel.Draw(CenterPoint, Radus); // Refresh calls Draw using the existing location data. wheel.Refresh();
// List of 'Entries' used for the wheel. wheel.EntryList; // Entry type contains a UniqueID(optional), Name, and Color. // Returns a unique ticket ID that can optionally be set in the Entry. wheel.EntryAdd(Entry); // Remove uses an ID provided by EntryAdd. wheel.EntryRemove(UniqueID); // Clear the EntryList. wheel.EntriesClear(); // Randomize the EntryList. wheel.ShuffleEntries();
// Returns true if the wheel is actively spinning. wheel.IsBusy; // Begin the spinning animation and random list pick. // Uses preset or default settings. wheel.Start(); // Or begin and set spin direction, spin type, and strength. wheel.Start(animDirection, randPowerType, randStrength); /* 'animDirection' can be Clockwise or CoutnerClockwise. 'randPowerType' can be Infinite, Weak, Average, Strong, Super, Random, or Manual. 'randStrength' is only used if 'randPowerType' is Manual. */ // Manually stop the picker and cancel the random pick. wheel.Stop(); // If 'randPowerType' is Infinite, then Stop will slow the picker and still select randomly from the list.
// Public function used to determine text color against the background. wheel.IsReadable(Color1, Color2); // Brings the PictureBox control to the front of the form. wheel.BringToFront(); // Sends the PictureBox control to the back of the form. wheel.SendToBack(); // Disposes of Image and PictureBox data. // Must create a new wheel object after this is called. wheel.Dispose();
// This event is called each frame the wheel is moved. // Entry returned is the currently selected entry on the wheel. ToolActionEventHandler(Entry, string actionInfo) /* The string array provided is a 4 part array. Example return values in quotes: Total Angles to turn. "1672" Current Angle. "1671.018" Current base speed adjustment. "-0.9000244" Spin Strength. "Random|4" */ // This event is called when the wheel comes to a stop. //Entry returned is the final selected Entry. ToolStopEventHandler(Entry)
// If false, actions will return null instead of throwing an Exception. wheel.AllowExceptions = true; // Contains all other wheel settings. wheel._ToolProperties; // See below section for all _ToolProperties settings:
wheel._ToolProperties.ArrowPosition wheel._ToolProperties.ArrowImage wheel._ToolProperties.LineColor wheel._ToolProperties.LineWidth wheel._ToolProperties.ForceUniqueEntryColors wheel._ToolProperties.TextToShow wheel._ToolProperties.TextColor wheel._ToolProperties.TextColorAuto wheel._ToolProperties.TextFontFamily wheel._ToolProperties.TextFontStyle wheel._ToolProperties.ShadowVisible wheel._ToolProperties.ShadowColor wheel._ToolProperties.ShadowPosition wheel._ToolProperties.ShadowLength wheel._ToolProperties.CenterVisible wheel._ToolProperties.CenterColor wheel._ToolProperties.CenterSize
Please feel free to view the source code over at GitHub. Completely available. Let me know if you have any questions or concerns. And please share with your friends!