C#学习笔记
1. 时间相关处理
DateTime d1,d2;
/*..给d1,d2赋值..*/
TimeSpan ts = d2 - d1; //使用TimeSpan可以获取2个时间相差的天数,小时,分,秒等
string str = ts.TotalDays.ToString();
int i = (d2.Year - d1.Year) * 12 + d2.Month - d1.Month;//2个时间相差的月数
/*..给d1,d2赋值..*/
TimeSpan ts = d2 - d1; //使用TimeSpan可以获取2个时间相差的天数,小时,分,秒等
string str = ts.TotalDays.ToString();
int i = (d2.Year - d1.Year) * 12 + d2.Month - d1.Month;//2个时间相差的月数
2. 控件的移动
private void plUI_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
xx = e.Location.X;
yy = e.Location.Y;
}
}
private void plUI_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
((Panel)(sender)).Left -= xx - e.X;
((Panel)(sender)).Top -= yy - e.Y;
}
}
{
if (e.Button == MouseButtons.Left)
{
xx = e.Location.X;
yy = e.Location.Y;
}
}
private void plUI_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
((Panel)(sender)).Left -= xx - e.X;
((Panel)(sender)).Top -= yy - e.Y;
}
}
3. 随机函数
Random rd = new Random(Environment.TickCount * i);
4. 组合键设置
![](/Images/OutliningIndicators/ContractedBlock.gif)