Skip to content

Instantly share code, notes, and snippets.

@polarstars
polarstars / Console.cs
Last active September 5, 2018 09:24
如何在Form中重定向Console输出到文件 #C#
public class ConsoleWriterEventArgs : EventArgs
{
public string Value { get; private set; }
public ConsoleWriterEventArgs(string value)
{
Value = value;
}
}
public class ConsoleWriter : TextWriter
@polarstars
polarstars / radDropDownList.cs
Created July 20, 2018 07:01
#Telerik 中 RadDropDownList 显示图片列表 #C#
花不啰嗦,直接看代码,数据绑定到DataTable上,如果有多个控件绑定到一个DataTable上,你又不需要控件之间联动,
请添加类似“ddList.BindingContext = new BindingContext();”的代码。
我看到国内很多人的帖子都是用的DataTable的Copy方法,在某些情况下能满足要求,如果DataTable数据是要变动的Copy
大法就GameOver了,还是多用内建的方法,很多功能微软都为我们考虑好了, 是我们自己学艺不精不甚了解罢了。
==========================================================================================================
RadDropDownList ddList = new RadDropDownList();
...............(其它属性设置省略)
ddList.BindingContext = new BindingContext();
ddList.DataSource = FilesDataTable;
@polarstars
polarstars / VS2013.md
Last active July 2, 2018 07:32
VS2013 常用快捷键 #VS #技巧
快捷键 说明
Ctrl+- 移动光标到上次位置或相反,比如定位一个函数,转到函数定义后想回到函数使用处,则用Ctrl+-,若又想回到函数定义处则可以按Shift+Ctrl+-
Ctrl+] 匹配选中的括号(大括号、小括号都行),在多层循环+判断语句时非常方便
Ctrl+Space 代码补全
Ctrl+Tab 在VS中切换打开的窗口,即切换各个文件
Ctrl+I 递增搜索,与Ctrl+F不同的是搜索期间不显示搜索对话框,且Ctrl+F搜索下一个直接按Enter即可,而Ctrl+I搜索下一个按Ctrl+I或F3,Esc退出,连续按两次Ctrl+I重复上次搜索
Ctrl+Shift+F 旧式的文件搜索对话框(与记事本中的搜索替换框差不多,可以替换)
Ctrl+F3 为当前选中的部分进行搜索(不需要再输入要搜索的内容)
Shift+Alt+Enter 最大化代码编写区域(代码全屏模式),即去掉所有其它辅助窗口 只留下代码编写窗口,再按一次返回到原来界面
@polarstars
polarstars / Markdown.md
Last active June 27, 2018 08:05
Markdown #说明

Markdown语法主要分为如下几大部分: 标题段落区块引用代码区块强调列表分割线链接图片反斜杠 \符号'`'

4.1 标题

两种形式:
1)使用=-标记一级和二级标题。

一级标题
=========
二级标题
---------

@polarstars
polarstars / FindControlByType.cs
Created June 27, 2018 07:41
查找控件包含的子控件(特定类型T) #C#
public static List<T> FindControlByType<T>(this Control mainControl, bool getAllChild = false) where T : Control
{
List<T> lt = new List<T>();
for (int i = 0; i < mainControl.Controls.Count; i++)
{
if (mainControl.Controls[i] is T) lt.Add((T)mainControl.Controls[i]);
if (getAllChild) lt.AddRange(FindControlByType<T>(mainControl.Controls[i], getAllChild));
}
return lt;
}
@polarstars
polarstars / ExtractDouble.cs
Created June 27, 2018 07:36
提取字符串中的浮点数 #C#
public static double ExtractDouble(this string str)
{
Regex Reg = new Regex(@"[-+]?[0-9]*\.?[0-9]+");
Match m = Reg.Match(str);
if (m.Success)
return Convert.ToDouble(m.Value);
else
return 0.0;
}
@polarstars
polarstars / CopyDirectory.cs
Created June 27, 2018 07:35
拷贝目录及子目录内容 #C#
public static void CopyDirectory(String sourcePath, String destinationPath)
{
DirectoryInfo info = new DirectoryInfo(sourcePath);
Directory.CreateDirectory(destinationPath);
foreach (FileSystemInfo fsi in info.GetFileSystemInfos())
{
String destName = Path.Combine(destinationPath, fsi.Name);
if (fsi is System.IO.FileInfo) //如果是文件,复制文件
File.Copy(fsi.FullName, destName);
@polarstars
polarstars / CheckNet.cs
Created June 27, 2018 07:33
判断系统是否安装了net3.5或4.0框架 #C#
public static bool IsDotNet35Installed()
{
bool ret = false;
RegistryKey rk = OpenSoftwareKey(@"\Microsoft\NET Framework Setup\NDP\v3.5");
if (rk != null)
{
ret = true;
rk.Close();
}
@polarstars
polarstars / UACHelper.CS
Last active June 27, 2018 07:25
程序中判断是否有管理员权限 #C#
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;