473,626 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12367
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:codeprojec t.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
ScrollBarRender er.DrawArrowBut ton() 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 _DownButtonStat us = 0;

public SpinControl()
{
this._UpButton = new Button();
this._DownButto n = new Button();
this._UpButton. Paint += new PaintEventHandl er(UpButton_Pai nt);
this._DownButto n.Paint += new PaintEventHandl er(DownButton_P aint);

this._UpButton. MouseDown += new
MouseEventHandl er(_UpButton_Mo useDown);
this._UpButton. MouseUp += new MouseEventHandl er(_UpButton_Mo useUp);

this._DownButto n.MouseDown += new
MouseEventHandl er(_DownButton_ MouseDown);
this._DownButto n.MouseUp += new
MouseEventHandl er(_DownButton_ MouseUp);

this._UpButton. MouseEnter += new EventHandler(_U pButton_MouseEn ter);
this._DownButto n.MouseEnter += new
EventHandler(_D ownButton_Mouse Enter);

this._UpButton. MouseLeave += new EventHandler(_U pButton_MouseLe ave);
this._DownButto n.MouseLeave += new
EventHandler(_D ownButton_Mouse Leave);

this.AjustArrow ButtonSize();
this.Controls.A dd(this._UpButt on);
this.Controls.A dd(this._DownBu tton);
this.Width = 20;
}

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

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

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

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

void _DownButton_Mou seUp(object sender, MouseEventArgs e)
{
_DownButtonStat us = 0;
}
void _DownButton_Mou seLeave(object sender, EventArgs e)
{
_DownButtonStat us = 0;

}
void _DownButton_Mou seDown(object sender, MouseEventArgs e)
{
_DownButtonStat us = 1;
}
void _DownButton_Mou seEnter(object sender, EventArgs e)
{
_DownButtonStat us = 2;
}

protected override void OnResize(EventA rgs e)
{
this.AjustArrow ButtonSize();
base.OnResize(e );
}

private void AjustArrowButto nSize()
{
this._UpButton. Size = this.Size;
this._DownButto n.Size = this.Size;
this._UpButton. Height /= 2;
this._DownButto n.Height /= 2;
this._DownButto n.Top = this._UpButton. Bottom;
}

void UpButton_Paint( object sender, PaintEventArgs e)
{
if (_UpButtonStatu s == 0 )
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpNormal);
}
else if (_UpButtonStatu s == 1)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpPressed);
}
else
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpHot);
}

}

void DownButton_Pain t(object sender, PaintEventArgs e)
{
if (_DownButtonSta tus == 0)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownNormal);
}
else if (_DownButtonSta tus == 1)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownPressed);
}
else
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. 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****@microsof t.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 ScrollBarRender er.DrawArrowBut ton() 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 _DownButtonStat us = 0;
Why create a new de facto enum type without even naming the constants? You
already have the System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState
enum which has exactly what you want, and you can avoid the if statements
later on.
>
public SpinControl()
{
this._UpButton = new Button();
this._DownButto n = new Button();
this._UpButton. Paint += new PaintEventHandl er(UpButton_Pai nt);
this._DownButto n.Paint += new
PaintEventHandl er(DownButton_P aint);

this._UpButton. MouseDown += new
MouseEventHandl er(_UpButton_Mo useDown);
this._UpButton. MouseUp += new
MouseEventHandl er(_UpButton_Mo useUp);

this._DownButto n.MouseDown += new
MouseEventHandl er(_DownButton_ MouseDown);
this._DownButto n.MouseUp += new
MouseEventHandl er(_DownButton_ MouseUp);

this._UpButton. MouseEnter += new
EventHandler(_U pButton_MouseEn ter);
this._DownButto n.MouseEnter += new
EventHandler(_D ownButton_Mouse Enter);

this._UpButton. MouseLeave += new
EventHandler(_U pButton_MouseLe ave);
this._DownButto n.MouseLeave += new
EventHandler(_D ownButton_Mouse Leave);

this.AjustArrow ButtonSize();
this.Controls.A dd(this._UpButt on);
this.Controls.A dd(this._DownBu tton);
this.Width = 20;
}

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

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

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

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

void _DownButton_Mou seUp(object sender, MouseEventArgs e)
{
_DownButtonStat us = 0;
}
void _DownButton_Mou seLeave(object sender, EventArgs e)
{
_DownButtonStat us = 0;

}
void _DownButton_Mou seDown(object sender, MouseEventArgs e)
{
_DownButtonStat us = 1;
}
void _DownButton_Mou seEnter(object sender, EventArgs e)
{
_DownButtonStat us = 2;
}

protected override void OnResize(EventA rgs e)
{
this.AjustArrow ButtonSize();
base.OnResize(e );
}

private void AjustArrowButto nSize()
{
this._UpButton. Size = this.Size;
this._DownButto n.Size = this.Size;
this._UpButton. Height /= 2;
this._DownButto n.Height /= 2;
this._DownButto n.Top = this._UpButton. Bottom;
}

void UpButton_Paint( object sender, PaintEventArgs e)
{
if (_UpButtonStatu s == 0 )
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpNormal);
}
else if (_UpButtonStatu s == 1)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpPressed);
}
else
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpHot);
}

}

void DownButton_Pain t(object sender, PaintEventArgs e)
{
if (_DownButtonSta tus == 0)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownNormal);
}
else if (_DownButtonSta tus == 1)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownPressed);
}
else
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle ,

System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. 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****@microsof t.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 ScrollBarArrowB uttonState enum,
I somehow ignore that.

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

private ScrollBarArrowB uttonState _UpButtonStatus ;
private ScrollBarArrowB uttonState _DownButtonStat us;

public SpinControl()
{
this._UpButton = new Button();
this._DownButto n = new Button();
this._UpButton. Paint += new PaintEventHandl er(UpButton_Pai nt);
this._DownButto n.Paint += new PaintEventHandl er(DownButton_P aint);

this._UpButton. MouseDown += new
MouseEventHandl er(_UpButton_Mo useDown);
this._UpButton. MouseUp += new MouseEventHandl er(_UpButton_Mo useUp);

this._DownButto n.MouseDown += new
MouseEventHandl er(_DownButton_ MouseDown);
this._DownButto n.MouseUp += new
MouseEventHandl er(_DownButton_ MouseUp);

this._UpButton. MouseEnter += new EventHandler(_U pButton_MouseEn ter);
this._DownButto n.MouseEnter += new
EventHandler(_D ownButton_Mouse Enter);

this._UpButton. MouseLeave += new EventHandler(_U pButton_MouseLe ave);
this._DownButto n.MouseLeave += new
EventHandler(_D ownButton_Mouse Leave);

this.AjustArrow ButtonSize();
this.Controls.A dd(this._UpButt on);
this.Controls.A dd(this._DownBu tton);
this.Width = 20;
}

void _UpButton_Mouse Leave(object sender, EventArgs e)
{
_UpButtonStatus = ScrollBarArrowB uttonState.UpNo rmal;
}

void _UpButton_Mouse Up(object sender, MouseEventArgs e)
{
_UpButtonStatus = ScrollBarArrowB uttonState.UpNo rmal;
}

void _UpButton_Mouse Down(object sender, MouseEventArgs e)
{
_UpButtonStatus = ScrollBarArrowB uttonState.UpPr essed;
}

void _UpButton_Mouse Enter(object sender, EventArgs e)
{
_UpButtonStatus = ScrollBarArrowB uttonState.UpHo t;
}

void _DownButton_Mou seUp(object sender, MouseEventArgs e)
{
_DownButtonStat us = ScrollBarArrowB uttonState.Down Normal;
}
void _DownButton_Mou seLeave(object sender, EventArgs e)
{
_DownButtonStat us = ScrollBarArrowB uttonState.Down Normal;

}
void _DownButton_Mou seDown(object sender, MouseEventArgs e)
{
_DownButtonStat us = ScrollBarArrowB uttonState.Down Pressed;
}
void _DownButton_Mou seEnter(object sender, EventArgs e)
{
_DownButtonStat us = ScrollBarArrowB uttonState.Down Hot;
}

protected override void OnResize(EventA rgs e)
{
this.AjustArrow ButtonSize();
base.OnResize(e );
}

private void AjustArrowButto nSize()
{
this._UpButton. Size = this.Size;
this._DownButto n.Size = this.Size;
this._UpButton. Height /= 2;
this._DownButto n.Height /= 2;
this._DownButto n.Top = this._UpButton. Bottom;
}

void UpButton_Paint( object sender, PaintEventArgs e)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle , _UpButtonStatus );
}

void DownButton_Pain t(object sender, PaintEventArgs e)
{
ScrollBarRender er.DrawArrowBut ton(e.Graphics,
this._UpButton. ClientRectangle , _DownButtonStat us);
}
}
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****@microsof t.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
6906
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 release the mouse button, the value in the textbox changes to where it incremented depending on the length of time I held the mouse button down. How do I make the value "spin" in the textbox while I hold the mouse button down? Thanks! Mark
1
1801
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 arrow, I get the month display but no time. Where can you specify the time Many Thanks to the Exper Peter
1
1537
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? The normal spin control ------ | up | ------- |down|
13
1586
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 time. The number of label controls will vary between 50 and 200. I have created an array of labels and placed them on the form. It works great, BUT I have not been able to raise any events for these controls. I made a small demo with 9 labels...
9
6095
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
1305
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 I can. There has to be some type of lite control out there that can handle this. I am hacked off that the RTF control will not read HTML. RTF tags are WAY too much work for what I need to do. --
2
1885
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 control contents to form a file name, i.e. spin #1 is page # and spin #2 is total number of pages, and the text control spells it out as
1
1322
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 control. The login button sticks out like a sore thumb on the bottom right. I'd rather hvae it be to the right of both the user name and password. Or at least center align it. How do I do this? Thanks in advance, --Amit
11
3932
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 motor that spins, but what we're having trouble with is figuring out how to program it. we want to be able to control the speed of the motor. how would we accomplish this? i'm new to all of this, so i'm having a hard time wrapping my mind
0
8711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.