开发过程中用到的一些知识

在后台给前台控件赋值16进制的颜色

控件名.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF54C0DC"));

 

wpf监控方法

Timer timer;

timer = new System.Threading.Timer(new TimerCallback(MyDelegate)); //实例化一个Timer时间器并启动
timer.Change(0, 1000);

delegate void UpdateTimer();

void MyDelegate(object state)
{
  this.Dispatcher.BeginInvoke(new UpdateTimer(MyEventFunc));
}
//需要实现的方法
void MyEventFunc()
{

}

 另外一种

DispatcherTimer t = null;
下面的可以写在load事件里面
t = new DispatcherTimer();
t.Interval = new TimeSpan(0, 0, 1);
t.Tick += OnTimer;
t.IsEnabled = true;
t.Start();

在别的地方实现OnTimer方法

 

C# 轻松获取路径中文件名、目录、扩展名等

   

string path = "C:\\dir1\\dir2\\foo.txt";  
string str = "GetFullPath:" + Path.GetFullPath(path) + "\r\n";
str += "GetDirectoryName:" + Path.GetDirectoryName(path) + "\r\n";
str += "GetFileName:" + Path.GetFileName(path) + "\r\n";
str += "GetFileNameWithoutExtension:" + Path.GetFileNameWithoutExtension(path) + "\r\n";
str += "GetExtension:" + Path.GetExtension(path) + "\r\n";
str += "GetPathRoot:" + Path.GetPathRoot(path) + "\r\n";
MessageBox.Show(str);
结果:
GetFullPath:C:\dir1\dir2\foo.txt
GetDirectoryName:C:\dir1\dir2
GetFileName:foo.txt
GetFileNameWithoutExtension:foo
GetExtension:.txt
GetPathRoot:C:\

 

posted @ 2015-06-15 15:06  红楼  阅读(188)  评论(0编辑  收藏  举报