See Also: SpinButton Members
A SpinButton is an ideal way to allow the user to enter a numeric value. Rather than having to directly type a number into an Gtk.Entry, a SpinButton allows the user to click on one of two arrows to increment or decrement the displayed value. A value can still be typed in, with the added benefit that it can be checked to ensure it is within a given range.
To precisely configure a SpinButton, an Gtk.Adjustment is used. Though it is not mandatory, its use allows fine control over the 'spinning' properties of the SpinButton.
A SpinButton is typically created by setting up an Gtk.Adjustment and passing that to the SpinButton's constructor. The value entered by a user can then be retrieved using either the SpinButton.Value property or the SpinButton.ValueAsInt property.
The following demonstrates how to get an integer from a SpinButton:
C# Example
// Creates a window with a spin button
public void CreateSpinButton()
{
Window window = new Window();
window.BorderWidth = 5;
// Create a spin button for percentage values.
SpinButton spinner = new SpinButton(0f, 100f, 1f);
spinner.ValueChanged += new EventHandler(OutputValue);
window.Add(spinner);
window.ShowAll();
}
// Handles ValueChanged events and writes to the console
private void OutputValue(object source, System.EventArgs args)
{
SpinButton spinner = source as SpinButton;
System.Console.WriteLine("Current value is: " + spinner.ValueAsInt);
}