Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Masked Textbox 24 Hour Clock

  1. #1

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Resolved [RESOLVED] [2005] Masked Textbox 24 Hour Clock

    I have a masked textbox on my form which has a format of 'hh:mm'

    However this gives me the time in 12 hour format whereas I want it in 24 hour format.

    From reading on the web I understand that if I change the format to 'HH:mm' then this will give me what I want - However this doesn't work (all it does is change the format back to hh:mm)

    Does anyone know how I can fix this ?

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Masked Textbox 24 Hour Clock

    Can you show your code?

    I know this isn't a masked textbox example but using this code works fine:

    Code:
            MessageBox.Show(Date.Now.ToString("hh:mm"))
    
            MessageBox.Show(Date.Now.ToString("HH:mm"))
    How are you doing the formatting??

    This should also work for the Masked textbox:
    Code:
      Me.MaskedTextBox1.Text = Date.Now.ToString("HH:mm")
    'Or
      Me.MaskedTextBox1.Text = Date.Now.ToString("hh:mm")
    Last edited by stimbo; Feb 27th, 2007 at 07:49 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2005] Masked Textbox 24 Hour Clock

    Quote Originally Posted by Jonny1409
    I have a masked textbox on my form which has a format of 'hh:mm'

    However this gives me the time in 12 hour format whereas I want it in 24 hour format.

    From reading on the web I understand that if I change the format to 'HH:mm' then this will give me what I want - However this doesn't work (all it does is change the format back to hh:mm)

    Does anyone know how I can fix this ?
    Hi,

    You could use the Clockmode Enumeration for that.
    Here's the link;

    http://msdn2.microsoft.com/en-us/lib...clockmode.aspx

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Masked Textbox 24 Hour Clock

    Is there any reason you can't use a datetimepicker?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Masked Textbox 24 Hour Clock

    Sparrow, you really should read those MSDN topics a little more carefully before posting. That page relates specifically to the POS for .NET SDK. Not many developers will have the Microsoft.PointOfService namespace available to them.

    As for displaying the time, I'd suggest using a DateTimePicker with the Format property set to Custom, the CustomFormat property set to "HH:mm" and the ShowUpDown property set to True. You can't set a MaskedTextBox to show specifically 24 hour time. The closest you can get is "00:00" for the mask, which still leaves the job of checking that the mask is full and validating the text to the developer. The DateTimePicker will do it all for you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] Masked Textbox 24 Hour Clock

    Hi Stimbo,

    I'm using the property as opposed to writing it in code. Thanks for the advice though.

    Sparrow, thanks for your advice, although I haven't yet looked at the link.

    Stanav and jmcilhinney, Thanks for your advice - I'll use a DateTimePicker instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width