Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to hide the numericUpDown control's up and down arrows?

4,143 views
Skip to first unread message

ABC

unread,
Jul 5, 2006, 11:35:50 AM7/5/06
to
How to hide the numericUpDown control's up and down arrows?

I only want the numeric textbox, but numericUpDown has up and down arrow is
not my want, how can I hide it?


Jared Parsons [MSFT]

unread,
Jul 5, 2006, 1:47:58 PM7/5/06
to
Hello ABC,

> How to hide the numericUpDown control's up and down arrows?
>
> I only want the numeric textbox, but numericUpDown has up and down
> arrow is not my want, how can I hide it?

I don't think that you can hide the arrows on the NumericUpDown control.

--
Jared Parsons [MSFT]
jare...@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.


Bob Powell [MVP]

unread,
Jul 5, 2006, 5:20:39 PM7/5/06
to
Just use a text box!

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"ABC" <a...@abc.com> wrote in message
news:%230mDyiE...@TK2MSFTNGP03.phx.gbl...

ABC

unread,
Jul 6, 2006, 12:55:46 AM7/6/06
to
but if I use textbox, it will accept any non-numeric characters.

"Bob Powell [MVP]" <bob@_spamkiller_.bobpowell.net> 撰寫於郵件新聞:OFj%23ajHoG...@TK2MSFTNGP02.phx.gbl...

Claes Bergefall

unread,
Jul 6, 2006, 10:57:52 AM7/6/06
to
Public Class TextBoxEx
Inherits TextBox
Private Const ES_NUMBER As Integer = &H2000

Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim params As CreateParams = MyBase.CreateParams
params.Style = params.Style Or ES_NUMBER
Return params
End Get
End Property

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As
Boolean
If keyData = (Keys.Shift Or Keys.Insert) OrElse keyData =
(Keys.Control Or Keys.V) Then
Dim data As IDataObject = Clipboard.GetDataObject
If data Is Nothing Then
Return MyBase.ProcessCmdKey(msg, keyData)
Else
Dim text As String =
CStr(data.GetData(DataFormats.StringFormat, True))
If text = String.Empty Then
Return MyBase.ProcessCmdKey(msg, keyData)
Else
For Each ch As Char In text.ToCharArray
If Not Char.IsNumber(ch) Then
Return True
End If
Next
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End If
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End Function
End Class

/claes

"ABC" <a...@abc.com> wrote in message

news:OdFHxhLo...@TK2MSFTNGP05.phx.gbl...

Rajesh

unread,
Jan 16, 2009, 12:57:17 AM1/16/09
to

CentauriBoy

unread,
Apr 8, 2009, 11:28:44 PM4/8/09
to
If you really wanted a NumericUpDown control without the arrow keys, take it one step further:

In Form_Load():

//////////////////////////////////////////////////////////////////////////
// Local variables.
int nArrowKeyWidth = myNumericUpDown.Controls[0].Width;

// 1) Set the border style to none. Otherwise a cut off portion can be seen.
myNumericUpDown.BorderStyle = BorderStyle.None;

// 2) Clip a new region which the user will use.
myNumericUpDown.Region = new System.Drawing.Region(new System.Drawing.Rectangle(0, 0, myNumericUpDown.Width - nArrowKeyWidth - 1, myNumericUpDown.Height));

// 3) Add an offset to the controls so that it will line up properly. (Optional)
myNumericUpDown.Location = new System.Drawing.Point(myNumericUpDown.Location.X + nArrowKeyWidth - 1,
myNumericUpDown.Location.Y);

// 4) Make a copy of the client rectangle for rendering a new border. (Optional, only if you want the border back.)
m_CopyOfRectangle = new System.Drawing.Rectangle(myNumericUpDown.Location.X - 2,
myNumericUpDown.Location.Y - 2,
myNumericUpDown.ClientRectangle.Width + 2 - nArrowKeyWidth,
myNumericUpDown.ClientRectangle.Height + 2);
// 5) Hide the arrows from being used.
myNumericUpDown.Controls[0].Hide();

// Store the graphics handle for rendering the border.
m_CopyOfGraphics = myForm.CreateGraphics();
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// Override myNumericUpDown Paint Event to render the border.
private void myNumericUpDown_Paint(object sender, PaintEventArgs e)
{
m_CopyOfGraphics.DrawRectangle(System.Drawing.Pens.CadetBlue, m_CopyOfRectangle);
}
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// Clean up!
private void Dispose()
{
m_CopyOfGraphics.Dispose();
}
//
//////////////////////////////////////////////////////////////////////////

Pros:
1) Less code to write.
2) No overriding key events.
3) No converting non-numeric keys.

Cons:
1) Requires storing a rectangle and/or graphics device for rendering a new border.
2) A Marked Text Box, using only int values, would be easier.
3) Other programmers will think you're crazy using this method.

Hope this helps!

From http://www.developmentnow.com/g/29_2009_1_0_0_783559/How-to-hide-the-numericUpDown-controls-up-and-down-arrows.htm

Deepa

unread,
Jun 12, 2009, 7:41:11 AM6/12/09
to

jib...@gmail.com

unread,
Jul 13, 2020, 12:30:42 AM7/13/20
to
Ya lo pude realizar, es facil.

numericUpDown1.BorderStyle = BorderStyle.None;
numericUpDown1.Controls[0].Hide();
numericUpDown1.Width = numericUpDown1.Width + 16;

Espero le sirva a muchos.

Saludos :)
0 new messages