12 Replies - 604 Views - Last Post: 08 October 2012 - 12:07 PM Rate Topic: -----

#1 inkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 26-June 12

Time up down buttons

Posted 08 October 2012 - 12:50 AM

Hi guys this isn't the usual technical questions more of a how would i do it. I am working on a small programme. I have a date time box which displays the time on screen. The program is going to be run off a touch screen. I would like a up down button that the user can change the time with is this possible?

Any one any hints or tips on creating programs that uses touch screens.

Thanks in advance Inkey.:)

Is This A Good Question/Topic? 0
  • +

Replies To: Time up down buttons

#2 inkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 26-June 12

Re: Time up down buttons

Posted 08 October 2012 - 02:36 AM

i have a textbox which i have made appear with the current date and time.

Timebox1.Text = DateTime.Now.ToString("hh mm");

Now i am trying to create a button that will increment the hours by +1

I have the following code which i am trying to do this with but i get a error saying "Error 4 Cannot implicitly convert type 'System.DateTime' to 'int'"

  private void BtnTimeUp_Click(object sender, EventArgs e)
        {
            int q  = Convert.ToDateTime(Timebox1);
           q = +1;

           Timebox1.Text = Convert.ToString(q);
           
        }


How would i go about trying to get the hour of the date to increment +1 when i click the button BtnTimeUp

Thanks Inkey.
Was This Post Helpful? 0
  • +
  • -

#3 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,539
  • Joined: 08-April 09

Re: Time up down buttons

Posted 08 October 2012 - 02:42 AM

Use the DateTime.Hour property to get Hours, it returns the int

http://msdn.microsof...etime.hour.aspx

Also, read about the ++ operator
http://msdn.microsof...(v=vs.100).aspx

This post has been edited by Michael26: 08 October 2012 - 02:45 AM

Was This Post Helpful? 0
  • +
  • -

#4 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 86
  • View blog
  • Posts: 189
  • Joined: 23-September 12

Re: Time up down buttons

Posted 08 October 2012 - 03:16 AM

Hello:

I've never tried (as I don't own any touch-device), but it looks like System.Windows.Input.TouchDevice is where you would start. This was added in .NET framework 4 and is part of presentationcore.dll, so it looks like you would have to make it WPF rather than WinForms.

Here's the .NET 4.5 documentation:
http://msdn.microsof...(v=vs.110).aspx

Also probably handy, 'Walkthrough: Creating Your First Touch Application', also from MSDN:
http://msdn.microsof...y/ee649090.aspx
Was This Post Helpful? 0
  • +
  • -

#5 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 272
  • View blog
  • Posts: 552
  • Joined: 07-July 10

Re: Time up down buttons

Posted 08 October 2012 - 04:11 AM

DateTime.Add
DateTime date = DateTime.Now; // get whatever date you want to change
TimeSpan time = new TimeSpan(1,0,0,0);
DateTime combined = date.Add(time);

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: Time up down buttons

Posted 08 October 2012 - 04:31 AM

You could also just use DateTime.AddHours where you supply it with an int of the number of hours to add or a negative number to subtract hours.
Was This Post Helpful? 1
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: Time up down buttons

Posted 08 October 2012 - 04:37 AM

Off the top of my head, I would think you could have a button that increments and a button the decrements for Hours & Minutes and then use the .AddHours and .AddMinutes of DateTime against the value of the DTP (supplying negative values into method will reduce the number)
Was This Post Helpful? 0
  • +
  • -

#8 inkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 26-June 12

Re: Time up down buttons

Posted 08 October 2012 - 06:47 AM

This is what i have so far and it doesn't seem to be working

    private void BtnTimeUp_Click(object sender, EventArgs e)
        {
            test1.AddHours(+1);
            Timebox1.Text = test1.ToString("hh mm");
        }

Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: Time up down buttons

Posted 08 October 2012 - 07:32 AM

What is test1?

The example described was to control a datetimepicker

something like:
       private void btnIncHrs_Click(object sender, EventArgs e)
        {
            dateTimePicker1.Value = dateTimePicker1.Value.AddHours(1);
        
        }


For future reference, The .Text property of a DTP holds a string representing what is displayed in the DTP
The .Value is a datetime type and regardless of what is displayed as the text will hold both a date and time, defaulting one or the other as needed.

This post has been edited by CharlieMay: 08 October 2012 - 07:39 AM

Was This Post Helpful? 1
  • +
  • -

#10 inkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 26-June 12

Re: Time up down buttons

Posted 08 October 2012 - 07:39 AM

View PostCharlieMay, on 08 October 2012 - 07:32 AM, said:

What is test1?

The example described was to control a datetimepicker

something like:
       private void btnIncHrs_Click(object sender, EventArgs e)
        {
            dateTimePicker1.Value = dateTimePicker1.Value.AddHours(1);
        
        }


thanks that works a treat
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Time up down buttons

Posted 08 October 2012 - 07:58 AM

View Postinkey, on 08 October 2012 - 02:47 PM, said:

This is what i have so far and it doesn't seem to be working

    private void BtnTimeUp_Click(object sender, EventArgs e)
        {
            test1.AddHours(+1);
            Timebox1.Text = test1.ToString("hh mm");
        }

Of course it doesn't work.
.AddHours() is a function that return a new DateTime instance, which you just discard by not storing anywhere.

This post has been edited by AdamSpeight2008: 08 October 2012 - 08:43 AM

Was This Post Helpful? 1
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Time up down buttons

Posted 08 October 2012 - 12:06 PM

View Postinkey, on 08 October 2012 - 03:36 AM, said:

i have a textbox which i have made appear with the current date and time.


I just want to point out that a lot of the trouble here is from using the wrong tool. Sure you can use a hammer to remove a bolt and nut, but its a lot easier if you use a wrench.

Why are you using a textbox for a data and time, when you could just use the DateTimePicker? That's its job. If you don't like the default format, you can set your own custom format.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#13 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Time up down buttons

Posted 08 October 2012 - 12:07 PM

Please don't open duplicate threads.
You already have this posted at:
http://www.dreaminco...5&#entry1718535

I'll merge the two threads.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1