📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinAppTest02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDateTime_Click(object sender, EventArgs e)
{
lblInfo.Text = "日期与时间方法及属性使用示例:";
lblInfo.Text += "\n获取当前日期字符串DateTime.Now.ToLongDateString( ):\n"
+ DateTime.Now.ToLongDateString();
lblInfo.Text += "\n获取当前时间字符串DateTime.Now.ToLongTimeString( ):\n"
+ DateTime.Now.ToLongTimeString();
lblInfo.Text += "\n获取当前日期字符串(2)DateTime.Now.ToShortDateString( ):\n"
+ DateTime.Now.ToShortDateString();
lblInfo.Text += "\n获取当前时间字符串(2)DateTime.Now.ToShortTimeString( ):\n"
+ DateTime.Now.ToShortTimeString();
/*
lblInfo.Text += "\n获取当前年份DateTime.Now.Year:"
+ DateTime.Now.Year;
lblInfo.Text += "\n获取当前小时DateTime.Now.Hour:"
+ DateTime.Now.Hour;*/
lblInfo.Text += "\n当前为星期几DateTime.Now.DayOfWeek:"
+ DateTime.Now.DayOfWeek;
lblInfo.Text += "\n当前为一年中的第几天DateTime.Now.DayOfYear:"
+ DateTime.Now.DayOfYear;
lblInfo.Text += "\n增减天数后的日期DateTime.Now.AddDays(1.5):"
+ DateTime.Now.AddDays(1.5);
/*
lblInfo.Text += "\n增减天数后的日期DateTime.Now.AddDays(-1.5):"
+ DateTime.Now.AddDays(-1.5);*/
}
private void btnMath_Click(object sender, EventArgs e)
{
lblInfo.Text = "数学方法及字段使用示例:";
lblInfo.Text += "\n字段,圆周率Math.PI:"
+ Math.PI;
lblInfo.Text += "\n求绝对值方法Math.Abs(-38.5):"
+ Math.Abs(-38.5);
lblInfo.Text += "\n求正弦值方法(30度)Math.Sin(Math.PI/6):"
+ Math.Sin(Math.PI / 6);
lblInfo.Text += "\n求余弦值方法(60度)Math.Cos(Math.PI/3):"
+ Math.Cos(Math.PI / 3);
lblInfo.Text += "\n求正切值方法(45度)Math.Tan(Math.PI/4):"
+ Math.Tan(Math.PI / 4);
lblInfo.Text += "\n求最大值方法Math.Max(3,2):"
+ Math.Max(3, 2);
lblInfo.Text += "\n求最小值方法Math.Min(3,2):"
+ Math.Min(3, 2);
lblInfo.Text += "\n求幂方法(3的平方)Math.Pow(3,2):"
+ Math.Pow(3, 2);
lblInfo.Text += "\n求保留小数值方法Math.Round(3.54):"
+ Math.Round(3.54);
lblInfo.Text += "\n求保留小数值方法(2)Math.Round(3.1415926,3):"
+ Math.Round(3.1415926, 3);
lblInfo.Text += "\n求平方根方法(2的平方根)Math.Sqrt(2):"
+ Math.Sqrt(2);
}
private void btnString_Click(object sender, EventArgs e)
{
lblInfo.Text = "字符串方法及属性使用示例:";
lblInfo.Text += "\n查找指定子串在字符串中的位置\"abCDeFg\".IndexOf(\"b\",0):"
+ "abCDeFg".IndexOf("b", 0);
lblInfo.Text += "\n在指定位置插入子串\"abCDeFg\".Insert(3,\"hij\"):"
+ "abCDeFg".Insert(3, "hij");
lblInfo.Text += "\n指定子串最后一次出现的位置\"abCDeFg\".LastIndexOf(\"F\")):"
+ "abCDeFg".LastIndexOf("F");
lblInfo.Text += "\n字符串中的字符数\"abCDeFg\".Length:"
+ "abCDeFg".Length;
lblInfo.Text += "\n移除子串\"abCDeFg\".Remove(3,2):"
+ "abCDeFg".Remove(3, 2);
lblInfo.Text += "\n替换子串\"abCDeFg\".Replace(\"eFg\",\"hij\"):"
+ "abCDeFg".Replace("eFg","hij");
lblInfo.Text += "\n截取子串\"abCDeFg\".Substring(3,4):"
+ "abCDeFg".Substring(3, 4);
lblInfo.Text += "\n字符串转小写\"abCDeFg\".ToLower( ):"
+ "abCDeFg".ToLower();
lblInfo.Text += "\n字符串转大写\"abCDeFg\".ToUpper( ):"
+ "abCDeFg".ToUpper();
}
private void btnRandom_Click(object sender, EventArgs e)
{
Random rn = new Random();
lblInfo.Text = "随机数方法使用示例(假设随机对象为rn):";
lblInfo.Text += "\n产生随机整数rn.Next( ):"
+ rn.Next();
lblInfo.Text += "\n产生0~100之间的随机整数rn.Next(100):"
+ rn.Next(100);
lblInfo.Text += "\n产生-100~100之间的随机整数rn.Next(-100, 100):"
+ rn.Next(-100, 100);
lblInfo.Text += "\n产生0.0~1.0之间的随机实数rn.NextDouble( ):"
+ rn.NextDouble();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -