473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Looking for C# Spin Control

Is there a control equivalent to the old Spin control? The one with two hour heads and an optional
textbox in the middle? The closest I can find is the NumericUpDown control and it's not the same as
the Spin control. I just want a sizeable up/down arrow pair.
Nov 18 '08 #1
4 12327
hi Stewart,

Stewart Berman wrote:
Is there a control equivalent to the old Spin control? The one with two hour heads and an optional
textbox in the middle? The closest I can find is the NumericUpDown control and it's not the same as
the Spin control. I just want a sizeable up/down arrow pair.
You may google for

c# spin control site:codeproject.com

this gives you some hits.
mfG
--stefan <--
Nov 18 '08 #2
Hello Stewart,

Thank you for using Microsoft Managed Newsgroup Service, my name is Zhi-Xin
Ye, it's my pleasure to work with you on this issue.

You can create an UserControl, put two buttons in it, one on the top and
the other on the bottom. Handle the Paint event of the buttons and use
ScrollBarRenderer.DrawArrowButton() method to draw arrows on the buttons.

For example:

========= Sample code for your information ==============

public class SpinControl : UserControl
{
private Button _UpButton;
private Button _DownButton;

//Button status 0:Normal, 1:Pressed; 2:Hot(Mouse Hover)
private int _UpButtonStatus = 0;
private int _DownButtonStatus = 0;

public SpinControl()
{
this._UpButton = new Button();
this._DownButton = new Button();
this._UpButton.Paint += new PaintEventHandler(UpButton_Paint);
this._DownButton.Paint += new PaintEventHandler(DownButton_Paint);

this._UpButton.MouseDown += new
MouseEventHandler(_UpButton_MouseDown);
this._UpButton.MouseUp += new MouseEventHandler(_UpButton_MouseUp);

this._DownButton.MouseDown += new
MouseEventHandler(_DownButton_MouseDown);
this._DownButton.MouseUp += new
MouseEventHandler(_DownButton_MouseUp);

this._UpButton.MouseEnter += new EventHandler(_UpButton_MouseEnter);
this._DownButton.MouseEnter += new
EventHandler(_DownButton_MouseEnter);

this._UpButton.MouseLeave += new EventHandler(_UpButton_MouseLeave);
this._DownButton.MouseLeave += new
EventHandler(_DownButton_MouseLeave);

this.AjustArrowButtonSize();
this.Controls.Add(this._UpButton);
this.Controls.Add(this._DownButton);
this.Width = 20;
}

void _UpButton_MouseLeave(object sender, EventArgs e)
{
_UpButtonStatus = 0;
}

void _UpButton_MouseUp(object sender, MouseEventArgs e)
{
_UpButtonStatus = 0;
}

void _UpButton_MouseDown(object sender, MouseEventArgs e)
{
_UpButtonStatus = 1;
}

void _UpButton_MouseEnter(object sender, EventArgs e)
{
_UpButtonStatus = 2;
}

void _DownButton_MouseUp(object sender, MouseEventArgs e)
{
_DownButtonStatus = 0;
}
void _DownButton_MouseLeave(object sender, EventArgs e)
{
_DownButtonStatus = 0;

}
void _DownButton_MouseDown(object sender, MouseEventArgs e)
{
_DownButtonStatus = 1;
}
void _DownButton_MouseEnter(object sender, EventArgs e)
{
_DownButtonStatus = 2;
}

protected override void OnResize(EventArgs e)
{
this.AjustArrowButtonSize();
base.OnResize(e);
}

private void AjustArrowButtonSize()
{
this._UpButton.Size = this.Size;
this._DownButton.Size = this.Size;
this._UpButton.Height /= 2;
this._DownButton.Height /= 2;
this._DownButton.Top = this._UpButton.Bottom;
}

void UpButton_Paint(object sender, PaintEventArgs e)
{
if (_UpButtonStatus == 0 )
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.UpNormal);
}
else if (_UpButtonStatus == 1)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.UpPressed);
}
else
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.UpHot);
}

}

void DownButton_Paint(object sender, PaintEventArgs e)
{
if (_DownButtonStatus == 0)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.DownNormal);
}
else if (_DownButtonStatus == 1)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.DownPressed);
}
else
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.DownHot);
}
}
}

===========================

If you have any questions or concerns, please feel free to let me know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. 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/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 18 '08 #3
Zhi-Xin Ye [MSFT] wrote:
Hello Stewart,

Thank you for using Microsoft Managed Newsgroup Service, my name is
Zhi-Xin Ye, it's my pleasure to work with you on this issue.

You can create an UserControl, put two buttons in it, one on the top
and the other on the bottom. Handle the Paint event of the buttons
and use ScrollBarRenderer.DrawArrowButton() method to draw arrows on
the buttons.

For example:

========= Sample code for your information ==============

public class SpinControl : UserControl
{
private Button _UpButton;
private Button _DownButton;

//Button status 0:Normal, 1:Pressed; 2:Hot(Mouse Hover)
private int _UpButtonStatus = 0;
private int _DownButtonStatus = 0;
Why create a new de facto enum type without even naming the constants? You
already have the System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState
enum which has exactly what you want, and you can avoid the if statements
later on.
>
public SpinControl()
{
this._UpButton = new Button();
this._DownButton = new Button();
this._UpButton.Paint += new PaintEventHandler(UpButton_Paint);
this._DownButton.Paint += new
PaintEventHandler(DownButton_Paint);

this._UpButton.MouseDown += new
MouseEventHandler(_UpButton_MouseDown);
this._UpButton.MouseUp += new
MouseEventHandler(_UpButton_MouseUp);

this._DownButton.MouseDown += new
MouseEventHandler(_DownButton_MouseDown);
this._DownButton.MouseUp += new
MouseEventHandler(_DownButton_MouseUp);

this._UpButton.MouseEnter += new
EventHandler(_UpButton_MouseEnter);
this._DownButton.MouseEnter += new
EventHandler(_DownButton_MouseEnter);

this._UpButton.MouseLeave += new
EventHandler(_UpButton_MouseLeave);
this._DownButton.MouseLeave += new
EventHandler(_DownButton_MouseLeave);

this.AjustArrowButtonSize();
this.Controls.Add(this._UpButton);
this.Controls.Add(this._DownButton);
this.Width = 20;
}

void _UpButton_MouseLeave(object sender, EventArgs e)
{
_UpButtonStatus = 0;
}

void _UpButton_MouseUp(object sender, MouseEventArgs e)
{
_UpButtonStatus = 0;
}

void _UpButton_MouseDown(object sender, MouseEventArgs e)
{
_UpButtonStatus = 1;
}

void _UpButton_MouseEnter(object sender, EventArgs e)
{
_UpButtonStatus = 2;
}

void _DownButton_MouseUp(object sender, MouseEventArgs e)
{
_DownButtonStatus = 0;
}
void _DownButton_MouseLeave(object sender, EventArgs e)
{
_DownButtonStatus = 0;

}
void _DownButton_MouseDown(object sender, MouseEventArgs e)
{
_DownButtonStatus = 1;
}
void _DownButton_MouseEnter(object sender, EventArgs e)
{
_DownButtonStatus = 2;
}

protected override void OnResize(EventArgs e)
{
this.AjustArrowButtonSize();
base.OnResize(e);
}

private void AjustArrowButtonSize()
{
this._UpButton.Size = this.Size;
this._DownButton.Size = this.Size;
this._UpButton.Height /= 2;
this._DownButton.Height /= 2;
this._DownButton.Top = this._UpButton.Bottom;
}

void UpButton_Paint(object sender, PaintEventArgs e)
{
if (_UpButtonStatus == 0 )
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.UpNormal);
}
else if (_UpButtonStatus == 1)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.UpPressed);
}
else
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.UpHot);
}

}

void DownButton_Paint(object sender, PaintEventArgs e)
{
if (_DownButtonStatus == 0)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.DownNormal);
}
else if (_DownButtonStatus == 1)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.DownPressed);
}
else
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle,

System.Windows.Forms.VisualStyles.ScrollBarArrowBu ttonState.DownHot);
}
}
}

===========================

If you have any questions or concerns, please feel free to let me
know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

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: ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. 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/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 19 '08 #4
Hi Ben,

You're right, it's more concise to use the ScrollBarArrowButtonState enum,
I somehow ignore that.

public class SpinControl : UserControl
{
private Button _UpButton;
private Button _DownButton;

private ScrollBarArrowButtonState _UpButtonStatus;
private ScrollBarArrowButtonState _DownButtonStatus;

public SpinControl()
{
this._UpButton = new Button();
this._DownButton = new Button();
this._UpButton.Paint += new PaintEventHandler(UpButton_Paint);
this._DownButton.Paint += new PaintEventHandler(DownButton_Paint);

this._UpButton.MouseDown += new
MouseEventHandler(_UpButton_MouseDown);
this._UpButton.MouseUp += new MouseEventHandler(_UpButton_MouseUp);

this._DownButton.MouseDown += new
MouseEventHandler(_DownButton_MouseDown);
this._DownButton.MouseUp += new
MouseEventHandler(_DownButton_MouseUp);

this._UpButton.MouseEnter += new EventHandler(_UpButton_MouseEnter);
this._DownButton.MouseEnter += new
EventHandler(_DownButton_MouseEnter);

this._UpButton.MouseLeave += new EventHandler(_UpButton_MouseLeave);
this._DownButton.MouseLeave += new
EventHandler(_DownButton_MouseLeave);

this.AjustArrowButtonSize();
this.Controls.Add(this._UpButton);
this.Controls.Add(this._DownButton);
this.Width = 20;
}

void _UpButton_MouseLeave(object sender, EventArgs e)
{
_UpButtonStatus = ScrollBarArrowButtonState.UpNormal;
}

void _UpButton_MouseUp(object sender, MouseEventArgs e)
{
_UpButtonStatus = ScrollBarArrowButtonState.UpNormal;
}

void _UpButton_MouseDown(object sender, MouseEventArgs e)
{
_UpButtonStatus = ScrollBarArrowButtonState.UpPressed;
}

void _UpButton_MouseEnter(object sender, EventArgs e)
{
_UpButtonStatus = ScrollBarArrowButtonState.UpHot;
}

void _DownButton_MouseUp(object sender, MouseEventArgs e)
{
_DownButtonStatus = ScrollBarArrowButtonState.DownNormal;
}
void _DownButton_MouseLeave(object sender, EventArgs e)
{
_DownButtonStatus = ScrollBarArrowButtonState.DownNormal;

}
void _DownButton_MouseDown(object sender, MouseEventArgs e)
{
_DownButtonStatus = ScrollBarArrowButtonState.DownPressed;
}
void _DownButton_MouseEnter(object sender, EventArgs e)
{
_DownButtonStatus = ScrollBarArrowButtonState.DownHot;
}

protected override void OnResize(EventArgs e)
{
this.AjustArrowButtonSize();
base.OnResize(e);
}

private void AjustArrowButtonSize()
{
this._UpButton.Size = this.Size;
this._DownButton.Size = this.Size;
this._UpButton.Height /= 2;
this._DownButton.Height /= 2;
this._DownButton.Top = this._UpButton.Bottom;
}

void UpButton_Paint(object sender, PaintEventArgs e)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle, _UpButtonStatus);
}

void DownButton_Paint(object sender, PaintEventArgs e)
{
ScrollBarRenderer.DrawArrowButton(e.Graphics,
this._UpButton.ClientRectangle, _DownButtonStatus);
}
}
Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

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:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
I have autorepeat turned on for a command button that increments the value in a textbox. When I click on the button and hold the mouse button down, the value in the textbox does not change. When I...
1
by: Peter | last post by:
Hello Thanks for reviewing my question. I would like to know how do you select the time in the DateTime picker control? I have the control's format set to Time. When you click on the down...
1
by: Ghost | last post by:
Hi all I hope in an answer that could help me about my problem. I'm creating a GUI in Visual C++ .NET and I'd like to split the "Spin Control" in two buttons, has someone some ideas to do this? ...
13
by: Bernie | last post by:
Sorry, but this ia another whine about VB.Net's lack of Control Arrays. I am new to VB.Net and I'm building an application that uses variable number of Label controls that are created at run...
9
by: Sarfaraz Khan | last post by:
Hello, anyone can guid me how we can handle and define control array in vb.net? Thanks & regards SARFARAZ KHAN
6
by: Ray Cassick \(Home\) | last post by:
I am looking for a control that displays simple HTML text (just basic tags, not active content needed). I know I can use the IE ActiveX control but really want to stay away from the headaches if...
2
by: Drily Lit Raga | last post by:
VC++ calls this a spin control, I think VB calls it an updown? Anyway it is the control with two arrows on the right for entering numeric values. I have another text control that uses the spin...
1
by: AmitKu | last post by:
Okay this may be a lame question, but is there a way for me to play around with the login control layout? Just messing around with the properties doesn't allow me to get a good looking login...
11
by: socialanxiety | last post by:
i hope someone here can help me. basically, me and my friend have a summer project. in this project, we need something that would basically function as a blender. we know we'll need to buy a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.