如何在文本框中显示日期到所选日期 [英] how to display day in textbox to selected date

查看:111
本文介绍了如何在文本框中显示日期到所选日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在文本框中显示日期以在另一个文本框中选择日期

how to display day in text box to selected date in another text box

Private Sub txtReadDate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtReadDate.TextChanged
    
      If IsDate(txtReadDate.Text) Then
          txtDay.Text = Format(txtReadDate.Text, "dddd")
      Else
          txtDay.Text = vbNullString
      End If
  End Sub



编辑(按OP)================

我遇到的问题是我不想按按钮.我只希望始终显示这一天.例如,如果默认值是文本框中的now(),则我希望文本框仅显示日期部分(星期一),而不必按任何按钮将其激活.当用户将txtbox更改为明天或何时,只要选择了新日期,我希望文本框显示所选日期的新日期值.

我正在使用VB.Net 2005,所以我对编程不熟悉,所以越轻松越好..我目前在学校学习VB,想尝试制作一个程序,我和我的朋友都可以在工作中使用.



EDIT (by OP) ================

The problem I am having is I don''t want to have to press a button. I just want the day to always be displayed. For example, If the default value is now() from the textbox, I want the textbox to display only the day portion (Monday) but not have to press any button to activate it. When the user changes the txtbox to tomorrow or whenever, as soon as the new date has been selected, I would like the textbox to display the new day value for the date selected.

I am using VB.Net 2005, and I am new to programming so the easier the better.. I''m currently in school learning VB and want to try to make a program that my friends and I can utilize at work. Any help would be greatly appreciated!!!

推荐答案

dateTime dt;
if (DateTime.TryParse(txtReadDate.Text))
{
    // if you want the day NUMBER
    txtDay.Text = dt.Day.ToString();
    // if youwant the name of the day (monday, tuesday, etc)
    txtDay.Text = dt.DayOfWeek;
    // if you want the day of the year (julian day)
    txtDay.Text = dt.DayOfYear.ToString();
}



编辑===================

为什么要使用文本框允许用户输入日期?改用DateTimePicker控件,并处理ValueChanged事件.然后在该处理程序中执行以下操作:



EDIT ====================

WHY are you using a textbox to allow the user to enter a date? Use the DateTimePicker control instead, and handle the ValueChanged event. and in that handler, do this:

Dim ctrl As DateTimePicker = CType(sender, DateTimePicker)
' if you want the day NUMBER
txtDay.Text = ctrl.Value.Day.ToString()
' if youwant the name of the day (monday, tuesday, etc)
txtDay.Text = ctrl.Value.DayOfWeek
' if you want the day of the year (julian day)
txtDay.Text = ctrl.Value.DayOfYear.ToString()


关注

http://stackoverflow.com/questions/6058398/display-day-name-with-time [ ^ ]
follow

http://stackoverflow.com/questions/6058398/display-day-name-with-time[^]


这篇关于如何在文本框中显示日期到所选日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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