Vb.net操纵文本框的当前时间是什么 [英] Vb.net manipulating textbox of what is the current time

查看:57
本文介绍了Vb.net操纵文本框的当前时间是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何操纵文本框? 编辑 form_load将如何检查时间并向用户提供最新的文本框?

为例如当它的

我认为我需要的逻辑是这样的。



how can i manipulate my textbox? Edit how will the form_load check the time and give the user whats textbox to use?
for like example when its
im thinking the logic of what i need is like this.

if its4pm then
textbox.text ="its 4 pm"
else if its10pm then
textbox.text = "its 10 pm"
end if





i认为它很简单,但我发现它令人困惑。



我尝试过:



i尝试了这个,但它给了我输出错误





i think its simple but i find it confusing.

What I have tried:

i tried this but it gives me an output error

Dim date1 As Date = #7:00:00 AM#
        Dim date2 As Date = #10:00:00 AM#
        Dim date3 As Date = #1:00:00 PM#
        Dim date4 As Date = #4:00:00 PM#
        Dim date5 As Date = #7:00:00 PM#

        If TimeOfDay = date5 Then
            TextBox1.Text = "here"
            TextBox6.Text = "here"
        ElseIf TimeOfDay = date4 Then
            TextBox2.Text = "here"
            TextBox7.Text = "here"
        ElseIf TimeOfDay = date3 Then
            TextBox3.Text = "here"
            TextBox8.Text = "here"
        ElseIf TimeOfDay = date2 Then
            TextBox4.Text = "here"
            TextBox9.Text = "here"
        ElseIf TimeOfDay = date1 Then
            TextBox5.Text = "here"
            TextBox10.Text = "here"
        End If

推荐答案

根据您的描述,下面是代码的外观,尽管我不确定您的意图。无论如何,你应该只包括小时和安培来进行比较。



Based on what you described, below is how the code should look like although I'm not sure what you intend is. Anyway, you should only include hours and ampm for comparison.

Dim date1 As Date = #7 AM#
        Dim date2 As Date = #10 AM#
        Dim date3 As Date = #3 PM#
        Dim date4 As Date = #4 PM#
        Dim date5 As Date = #2 PM#

        Dim TimeOfDay = DateTime.Now.ToString("HH tt")

        If TimeOfDay = date5 Then
            TextBox1.Text = "here"
            TextBox6.Text = "here"
        ElseIf TimeOfDay = date4 Then
            TextBox2.Text = "here"
            TextBox7.Text = "here"
        ElseIf TimeOfDay = date3 Then
            TextBox3.Text = "here"
            TextBox8.Text = "here"
        ElseIf TimeOfDay = date2 Then
            TextBox4.Text = "here"
            TextBox9.Text = "here"
        ElseIf TimeOfDay = date1 Then
            TextBox5.Text = "here"
            TextBox10.Text = "here"
        End If


您的问题不是特别清楚。如果您只想在单个文本框中显示当前时间,请使用:

Your question is not particularly clear. If you just want to show the current time in a single textbox, use:
textbox.Text = String.Format("It's {0:h tt}", DateTime.Now)

自定义日期和时间格式字符串 [ ^ ]



如果你想要别的东西,那么你需要解释你的要求。

Custom Date and Time Format Strings[^]

If you want something else, then you're going to need to explain your requirements.


这篇关于Vb.net操纵文本框的当前时间是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆