473,545 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to spin the date (a new control in C#)

I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What I need
to do is to spin date (+- one day). How to do that? Moreover, I want a user
to type the date as well. So the control should validate the typed values on
the fly. Is it possible?
Mar 13 '07 #1
3 2842
Yes.
Create a UserControl and add a datetimepicker and a button above and below.
Hook up the buttons to an event and in the event set the "Value" property of
the datetimepicker to the current Value.AddDay(1) or Value.AddDay(-1)
depending on if the button will make the date go up or down.
If you specify that the format used in the datetimepicker is "Custom" then
you can specify a CustomFormat string, like "MM/dd/yy" for US time. The user
will be able to type into this control although they will have to use the
arrow keys to change which part of the date they are editing. A hidden
benefit is that they can also use the Arrow Up and Down keys to move the
selected part of the date "up" or "down".
The datetimepicker also has inbuilt validation.
"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:AD******** *************** ***********@mic rosoft.com...
I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What I
need
to do is to spin date (+- one day). How to do that? Moreover, I want a
user
to type the date as well. So the control should validate the typed values
on
the fly. Is it possible?

Mar 13 '07 #2
Is there a different way? I did it this way (but unfortunatelly without
letting user type the date). I put textbox (read only) and numericupdown
control. It works ok.
But how to validate (during typing) values typed (by a user) into the textbox?


"Simon Tamman" wrote:
Yes.
Create a UserControl and add a datetimepicker and a button above and below.
Hook up the buttons to an event and in the event set the "Value" property of
the datetimepicker to the current Value.AddDay(1) or Value.AddDay(-1)
depending on if the button will make the date go up or down.
If you specify that the format used in the datetimepicker is "Custom" then
you can specify a CustomFormat string, like "MM/dd/yy" for US time. The user
will be able to type into this control although they will have to use the
arrow keys to change which part of the date they are editing. A hidden
benefit is that they can also use the Arrow Up and Down keys to move the
selected part of the date "up" or "down".
The datetimepicker also has inbuilt validation.
"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:AD******** *************** ***********@mic rosoft.com...
I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What I
need
to do is to spin date (+- one day). How to do that? Moreover, I want a
user
to type the date as well. So the control should validate the typed values
on
the fly. Is it possible?


Mar 13 '07 #3
Well I only pressed the datetimepicker to avoid having to write your own
logic for the textbox as that's more cumbersome.

If you hook up to the KeyPress or KeyUp event on the textbox you'll be able
to perform the validation during typing but remaining logic will be rather
complicated (e.g. to work out via the location of the focus and which part
of the date they're writing and then validate their input) .

What would be easier is to use the TextBox Enter and Leave events to
validate the date once they've finishing typing it. You could then validate
the date by calling DateTime.TryPar se(). If the date is invalid put the
original value back into the textbox.

Failing that you could search on Google for such a control, perhaps someone
has already done all the work for you?

If you do end up writing the logic for the validation of the date in the
textbox.KeyPres s or KeyUp event be sure to use DateTime.IsLeap Year for your
leap year validation.

HTH

Simon

"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:4E******** *************** ***********@mic rosoft.com...
Is there a different way? I did it this way (but unfortunatelly without
letting user type the date). I put textbox (read only) and numericupdown
control. It works ok.
But how to validate (during typing) values typed (by a user) into the
textbox?
>

"Simon Tamman" wrote:
Yes.
Create a UserControl and add a datetimepicker and a button above and
below.
Hook up the buttons to an event and in the event set the "Value"
property of
the datetimepicker to the current Value.AddDay(1) or Value.AddDay(-1)
depending on if the button will make the date go up or down.
If you specify that the format used in the datetimepicker is "Custom"
then
you can specify a CustomFormat string, like "MM/dd/yy" for US time. The
user
will be able to type into this control although they will have to use
the
arrow keys to change which part of the date they are editing. A hidden
benefit is that they can also use the Arrow Up and Down keys to move the
selected part of the date "up" or "down".
The datetimepicker also has inbuilt validation.
"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:AD******** *************** ***********@mic rosoft.com...
I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What
I
need
to do is to spin date (+- one day). How to do that? Moreover, I want a
user
to type the date as well. So the control should validate the typed
values
on
the fly. Is it possible?

Mar 13 '07 #4

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

Similar topics

5
3415
by: Larry R Harrison Jr | last post by:
I use the Lebans calendar control and love it; the only thing is that it commonly starts out at the year 1899 rather than the current year. Is there a way to specifically tell it to start at the current date instead? Note: it does this fine if I'm using it in the context of a form's text box, but I'm trying to use it on a module which is...
2
6899
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...
1
1530
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|
2
1879
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
6
12531
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a calendar control to allow my users to enter a date but I need them to enter a time as well. It doesn't look like the calendar control will allow...
10
2824
by: sandraz444 | last post by:
I have an expression in the query under my form to autofill the date under a certain condition but it wont write to the underlying table?? The date shows in the form but not the table. Does anyone know a solution for this? Thanks!
0
2826
by: fredloh | last post by:
i have a tab control on my form. i then have several microsoft date and time picker control on the tab control. when i select a date on any of the date and time picker control, the result of the control's value is always 12:00:00 am instead of the date i selected even though the date displays correctly on the date and time picker control. the...
2
2274
by: Unter | last post by:
Hi everyone - can someone tell me please how to get the NumericUpDown control to increase/decrease values quickly - by default it increases by the increment value and in VB6 we used to use code to make it spin - am I missing a property? Many Thanks as usual
4
12352
by: Stewart Berman | last post by:
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.
0
7468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7808
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...
1
5329
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...
0
4945
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...
0
3450
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...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.