All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET获取电脑名、IP及用户名_[Asp.Net教程]
从多个位置截取字符串的SQL语句_[SQL Server教程]
浅谈,DotNet,保护中字符串加密的技术_.net资料_编程技术
C#使用foreach来读取记录_[Asp.Net教程]
安装使用MySQL时一个典型错误的解决_php资料_编程技术
SQL2000查询分析器中快捷键_mssql学习_编程技术
ASP.NET技巧:获取数据行数据信息_.net资料_编程技术
ASP.NET(C#)实现一次性上传多张图片(多个文件)_[Asp.Net教程]
解决JSP开发Web程序中的中文问题_[PHP教程]
.net下用javascript调用webservice_[Asp.Net教程]
Reading number is top 10 pictures
Beauty shocked Japan Tokyo motor show model
张家界的玻璃桥
A man's favorite things8
你白吃了多少药
The beginning and end
Sora aoi on twitter4
The Soviet union swimsuit exposure in the 70 year2
The money of more than 100 countries and regions15
Street street fighting
The money of more than 100 countries and regions4
Download software ranking
apache-tomcat-6.0.33
C++教程第四版
Twenty piece of palm leaf
软件工程思想
Boxer vs Yellow4
Unix video tutorial6
变速齿轮3.26
The Bermuda triangle1
DreamWeaver8
Desire a peach blossom
qq published in(发表于) 2014/7/11 9:16:09 Edit(编辑)
C#中DateTimePicker控件应用实例

C#中DateTimePicker控件应用实例

C#中DateTimePicker控件应用实例

DateTimePicker控件

功能

用户可以从日期或时间列表中选择单个项,用来表示日期。该控件显示为两部分:一部分为下拉列表(以文本形式表示的日期),另一部分为网格(在单击列表旁边的向下箭头时显示)。图1为DateTimePicker控件。



图1 DateTimePicker控件

2.属性

DateTimePicker控件常用属性及说明如表1所示。



表1 DateTimePicker控件常用属性及说明

下面详细介绍Value属性,此属性是指当前控件的日期或时间值。

语法:

public DateTime Value { get; set; }

属性值:分配给控件的DateTime值。

说明:如果Value属性未在代码中或被用户更改,它将设置为当前的日期和时间(DateTime.Now)。

示例

使用Value属性获得控件当前选中值

本示例通过使用Value属性,把控件当前选中的值赋给一个文本框。

程序主要代码如下:

textBox1.Text = dateTimePicker1.Value.ToString();

3.方法

ToString方法用于返回表示当前DateTimePicker控件的字符串。

语法:

public override string ToString ()

返回值:返回表示当前DateTimePicker的字符串,该字符串包括该控件的类型和Value属性。

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_13

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmData());

}

}

}

★★★★★frmData窗体设计文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _8_13

{

public partial class frmData : Form

{

public frmData()

{

InitializeComponent();

}

private void dateTimePicker1_CloseUp(object sender, EventArgs e)

{

this.textBox1.Text = dateTimePicker1.Value.ToString();

}

private void button1_Click(object sender, EventArgs e)

{

}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)

{

}

private void frmData_Load(object sender, EventArgs e)

{

}

}

}

★★★★★frmData窗体代码文件完整程序代码★★★★★

namespace _8_13

{

partial class frmData

{

///

/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();

this.textBox1 = new System.Windows.Forms.TextBox();

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// dateTimePicker1

//

this.dateTimePicker1.CustomFormat = "yyyy-mm-dd";

this.dateTimePicker1.Location = new System.Drawing.Point(36, 41);

this.dateTimePicker1.Name = "dateTimePicker1";

this.dateTimePicker1.Size = new System.Drawing.Size(126, 21);

this.dateTimePicker1.TabIndex = 0;

this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);

this.dateTimePicker1.CloseUp += new System.EventHandler(this.dateTimePicker1_CloseUp);

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point(36, 80);


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.