1.日期相关

获取英文月份名称 : DateTime.Now.ToString("MMMM")

1.1 各个字母所代表的意思

1.MM:月份 2.mm:分钟 3. MMMM:文字形式月份 4.MMM:三个字母缩写的月份

4.HH:24小时制 5.hh:12小时制

6.ddd:三个字母缩写的星期 7.dddd:完整的星期

8.t: 单字母 A.M./P.M. 缩写(A.M. 将显示为“A”) 9.tt:两字母 A.M./P.M. 缩写(A.M. 将显示为“AM”)

9.zz 时区(eg:+8)

10.d (eg:11/3/2017)

2. 拖拽图片显示到 PictureBox中

首先 修改窗体的 AllowDrop 属性为true ,然后在 DragEnter 事件中写下如下代码,实际上就是获取存放拖放文件的本地路径

        private void FrmAddFood_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;//设置拖放操作中目标放置类型为复制
string[] str_Drop = (string[])e.Data.GetData(DataFormats.FileDrop, true);//拖放的多个文件的路径列表
string tempstr = str_Drop[0];//获取拖放第一个文件的路径
try
{
Image img = Image.FromFile(tempstr);//存储拖放的图片
pic.Image = img;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

3.string数组转换为int数组

 string[] strs = { "1", "2", "3" };
int[] nums = Array.ConvertAll<string, int>(strs, t => int.Parse(t));

4.获取屏幕尺寸

    //不包含任务栏
int width1 = SystemInformation.WorkingArea.Width;
int height1 = SystemInformation.WorkingArea.Height; //包含任务栏
int width2 = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
int height2 = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

5.压缩图片,生成缩略图

 /// <summary>
/// 生成缩略图
/// </summary>
/// <param name="sourceImage">源图</param>
/// <param name="width">新图宽</param>
/// <param name="height">新图高</param>
/// <returns>新图</returns>
public Image GetReducedImage(Image sourceImage, int width, int height)
{
Bitmap bitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bitmap);
g.Clear(Color.Transparent); //清空背景图,以透明色填充
//在新图片的指定位置绘制指定大小的原图片对象
g.DrawImage(sourceImage, new Rectangle(0, 0, width, height));
return bitmap;
}

方式二:

img.GetThumbnailImage(width, height, null, IntPtr.Zero);

6.货币格式字符串转换为 Int

  int str= int.Parse("$123,123.00", System.Globalization.NumberStyles.AllowThousands| System.Globalization.NumberStyles.AllowDecimalPoint|  ystem.Globalization.NumberStyles.AllowCurrencySymbol);

7.修改配置文件

    private void SetAppSetting(string key, string value)
{
// 1.Debug目录下的配置文件
Configuration config = ConfigurationManager.OpenExeConfiguration("UI.exe");
config.AppSettings.Settings[key].Value = value;
config.Save(); // 2.项目目录下的配置文件
//获取配置文件目录
string path = Environment.CurrentDirectory;
path = path.Substring(0, path.Length - 9) + "App.config";
//修改指定属性值
XDocument doc = XDocument.Load(path);
var rts = doc.Root.Element("appSettings");
rts.Elements().Single(t => t.Attribute("key").Value == key).Attribute("value").Value = value;
doc.Save(path);
}

8.获取当前程序运行绝对路径

Environment.CurrentDirectory

9.无边框窗体拖动实现

    int x;
int y;
private void Item_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
}
private void Item_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Location = new Point(this.Location.X + (e.X - this.x), this.Location.Y + (e.Y - this.y));
}
}

10.转换Linq结果集为 DataTable

        public static DataTable ToDataTable<T>(IEnumerable<T> ds)
{
DataTable dt = new DataTable();
//Column Name
foreach (var item in ds.First().GetType().GetProperties())
{
dt.Columns.Add(item.Name);
}
//Datarow
foreach (var item in ds)
{
DataRow dr = dt.NewRow();
foreach (DataColumn col in dt.Columns)
{
dr[col.ColumnName] = item.GetType().GetProperty(col.ColumnName).GetValue(item);
}
dt.Rows.Add(dr);
}
return dt;
}

11.生成唯一字符串

Guid.NewGuid().ToString("N");

12. C#实现中国式四舍五入

Math.Round(123.125, 2, MidpointRounding.AwayFromZero);

C#-常用知识点的更多相关文章

  1. DB2_SQL_常用知识点&实践

    DB2_SQL_常用知识点&实践 一.删除表中的数据(delete或truncate) 1 truncate table T_USER immediate; 说明:Truncate是一个能够快 ...

  2. JAVA常用知识点及面试题总结

    1. String.StringBuffer.StringBuilder三者区别? (1)三者在执行速率上的比较: String<StringBuffer<StringBuilder 原因 ...

  3. HTML常用知识点代码演示

    1 HTML部分常用知识点 <!-- 版本声明 --> <!DOCTYPE html> <!-- 唯一根元素 --> <html> <!-- 对网 ...

  4. Java 常用知识点

    Java 常用知识点 1.日期格式化 SimpleDateFormat Date date=new Date(System.currentTimeMillis()) ; SimpleDateForma ...

  5. Less常用知识点

    上篇文章介绍了如何安装Less,我们将所有东西都写在.less里面,最后通过命令将.less转换成.css文件,就可以放入到项目里用了.今天了解一些less常用知识点. 1.变量:声明两个变量,一个是 ...

  6. BIOS备忘录之EC常用知识点

    BIOS工程师眼中常用的EC知识点汇总: EC的硬件架构 EC硬件结构上主要分为两部分:Host Domain和EC Domain Host Domain就是通过LPC与CPU通信的部分(LPC部分需 ...

  7. YII2常用知识点总结

    YII2常用知识点总结 (一)总结性语句 (1)经常看看yii源码比如vendor\yiisoft\yii2\web这个目录(很重要)下的文件中的方法(这些文件中的公共方法,大致看了下基本上都可以通过 ...

  8. CSS3常用知识点

    CSS3常用知识点 1 css3选择器 1.1 属性选择器 /* E[attr~=val] 表示的一个单独的属性值 这个属性值是以空格分隔的*/ .attr2 a[class~="kawa& ...

  9. javaScript常用知识点有哪些

    javaScript常用知识点有哪些 一.总结 一句话总结:int = ~~myVar, // to integer | 是二进制或, x|0 永远等于x:^为异或,同0异1,所以 x^0 还是永远等 ...

  10. 一文学会 TypeScript 的 82% 常用知识点(下)

    一文学会 TypeScript 的 82% 常用知识点(下) 前端专栏 2019-11-23 18:39:08     都已经 9021 年了,TypeScript(以下简称 TS)作为前端工程师不得 ...

随机推荐

  1. Java之递归方法的字符串回文问题

    日期:2018.10.12 星期五 博客期:018 题目: 题目分析:本题目因为是要求用递归的,所以大类里就写一个递归方法,在主方法里用字符串调用这个方法就好了!这是大致这个类的框架定位,然后定位我们 ...

  2. python自动化-unittest批量执行用例(discover)

    前言 我们在写用例的时候,单个脚本的用例好执行,那么多个脚本的时候,如何批量执行呢?这时候就需要用到unittet里面的discover方法来加载用例了. 加载用例后,用unittest里面的Text ...

  3. jquery----Ajax补充

    jquery实现ajax请求 <script> //$.ajax的两种使用方式: //$.ajax(settings); //$.ajax(url,[settings]); $(" ...

  4. cf842D 01字典树|线段树 模板见hdu4825

    一般异或问题都可以转换成字典树的问题,,我一开始的想法有点小问题,改一下就好了 下面的代码是逆向建树的,数据量大就不行 /*3 01字典树 根据异或性质,a1!=a2 ==> a1^x1^..^ ...

  5. pycharm提示This inspection detects instance attribute definition outside __init__ method

    示例代码: class MiNiCarStore(CarStore): def createCar(self, typeName): self.carFactory = CarFactory() # ...

  6. ajax之阴影效果实现(对象函数方法)

    shadow.js文件内容jQuery.fn.shadow = function () { //获取到每个已封装的元素 //this表示jQuery对象 this.each(function () { ...

  7. C++ Primer 笔记——嵌套类 局部类

    1.嵌套类是一个独立的类,与外层类基本没什么关系.特别的是,外层类的对象和嵌套类的对象是相互独立的.在嵌套类的对象中不包含任何外层类定义的成员,在外层类的对象中也不包含任何嵌套类定义的成员. 2.嵌套 ...

  8. logical_backup: expdp/impdp

    Table of Contents 1. 注意事项 2. 前期准备 3. 常用参数及示例 4. 常用语句示例 5. 交互式命令 6. 技巧 6.1. 不生成文件直接导入目标数据库 6.2. 通过she ...

  9. spring cloud 容错之zuul回退和Zuul过滤器

    一.容错:Zuul回退 如果微服务下线了,针对每个微服务,都需要回复一个中文提示,而不是报异常 1.新建ConsumerFallbackProvider.java package com.pupeiy ...

  10. 蓝桥杯  历届试题 剪格子  dfs

    历届试题 剪格子 时间限制:1.0s   内存限制:256.0MB 问题描述 如下图所示,3 x 3 的格子中填写了一些整数. +--*--+--+ |10* 1|52| +--****--+ |20 ...