2008年11月6日星期四
Refactor in C#
1, VS2008 itself provides:
2, A FREE tool, CodeRushX
2008年10月31日星期五
PDC2008
The Future of C#
Microsoft Visual C++: 10 Is the New 6
Framework Design Guidlines
to be continued ...
2008年9月27日星期六
C# 中的 ?? 操作符有什么用?
场景介绍:
程序存储一些用户设定到一个文件中,这些设置被分为多个集合,分别包装成class,每个集合中的值项被定义为property。如果取property为null,则可以认为文件中不存在该值得记录。
示例代码:
public class MySettings
{
public string NumOfPoints{ get; set; }
}
public class UserPreferences
{
public MySettings Settings{ get; set; }
}
class Program
{
static void Main(string[] args)
{
UserPreferences option = new UserPreferences();
string num = option.MySettings01 ?? 10; // only ONE line
}
}
class Program
{
static void Main(string[] args)
{
UserPreferences option = new UserPreferences();
// THREE lines!
string num = 10;
if( option.MySettings01 != null )
num = option.MySettings01.NumOfPoints;
}
}
总结:
C#中的操作符 ?? 在处理 property 为 null 时可以简化代码。
2008年9月23日星期二
2008年8月24日星期日
Introduce WPF UI Automation Test
2008年8月12日星期二
C# code snippets
1, dowload snippets, here is some provided by MS, here is some provied by Dr.WPF;
2, use code snippets manager import them;
3, right click mouse where you want to insert codes;
4, select the snippet;
5, see, the codes added!
Now, you may curious about how to create your own snippets. Here can help you to get start.
2008年8月11日星期一
Use "HP Quick Lanch Buttons"
I have seen this small rocket for almost 2 years, but I learnt to use it only few days ago.
One function I like is "ZOOM". When you use 1680 * 1050 screen resolution, you may want to use large font. Here is the quicker way than change screen properties. I change this frequently because I am using dual monitors.
Another function I like is the quick buttons. There is button, a circle around a question mark, on the left top of your laptop keybord. Press the button, you get the button menus. Right click on the small rocket, you can "Adjust HP Quick Lanch Buttons Properties".
2008年7月30日星期三
Visula Studio Tips
2008年7月22日星期二
Expression Blend Tips
2008年7月9日星期三
Use Google Reader read RSS
2008年7月7日星期一
Minimun Windows Version for VC2008
Origin : in Chinese, in English
---- from MSDN ---
Visual C++ 概念:移植和升级
如何:修改 WINVER 和 _WIN32_WINNT
从 Visual C++ 2008 开始,Visual C++ 不支持面向 Windows 95、Windows 98、Windows ME 或 Windows NT。如果您的 WINVER 或 _WIN32_WINNT 宏被指定到这些 Windows 版本之一,则需要修改宏。当升级从 Visual C++ 的以前版本创建的项目时,如果将 WINVER 或 _WIN32_WINNT 宏指定到不再受支持的 Windows 版本,可能会看到与这些宏相关的编译错误。
2008年7月6日星期日
New Updates to MFC in VS2008
2008年7月4日星期五
WPF ?
To develop WPF application, you need these dev tools:
1, Visual Studio 2008 (or 2005 with some sp);
2, Microsoft Expression Blend, for the GUI programming, if you never heard it, google it.
2008年7月3日星期四
The power of UserControl
Senario 1:
You need display a image in your program. You can use xaml only, or you can use C# codes only. In some cases, combine xaml and Csharp is powerful. First you create a UserControl which only contain the picture, then you get a new class. In Cshap codes, you just "new" one instance.
If you create a image use codes only, you need there lines at least:
Image img = new Image();
BitmapFrame bmp = BitmapFrame.Create(new Uri(@"C:\myImage.jpg", UriKind.RelativeOrAbsolute));
img.Source = bmp;
img.Stretch = Stretch.Fill;
But, use expression blend, you can create a new user control just by several mouse click. Then in codes, just one line:
new MyImage();
Data Binding
Data Binding is a key concept in WPF.
Why I can NOT data bind my class ?
public class MyClass
{
public string MyPorperty { get; set; }
}
First time, I trid to bind MyProperty in MyClass to a TextBox, but I can NOT. Why? Because I did not derived my class from interface INotifyPropertyChanged.
public class MyClass : INotifyPropertyChanged
{...}
Yes, we have to implement the interface. Csharp is a great programming language, but not magician words. So when your data changed, you have to tell the framework the change happened. That's why you need the interface.
Same reason, when you implement you own collection class, you have implement the INotifyCollectionChanged. You may encounter some problem when you want to bind a List to ComboBox/ListBox/ListView. No, you are using the wrong class, you should use ObservableCollection instead.
Use ValidationRule to check your input
-
Let's use TextBox as a sample. You can set a validation rule to the binding. When the rule check failed, a red ring will around the text box.
Related classes: System.Windows.Data.Binding, System.Windows.Controls.ValidationRule
-------------------------------------------
Some Other Good Readings:
2008年7月2日星期三
Regular Expression
Senario:
We need user to input string in a text box, the string represent a frequency value, like "10.000 MHz".
Validation rule: (top down are the charaters can legally show in the string)
0 to N spaces
0 to N figure(0,1,2...9)
0 or 1 dot
1 to N figures
0 to N spaces
0 or 1 letter(the letter could be k, K, m, M, g, G)
0 or 1 letter(h or H)
0 or 1 letter(z or Z)
0 to N spaces.
C# Codes:
Regex r = new Regex(@"^\s*\d*[.]?\d+\s*[kKmMgG]?[hH]?[zZ]?\s*$");
Match m = r.Match(" 20000000000 ghz");
if (m.Success)
{
Console.WriteLine("Found match at position " + m.Index);
}
What simple! You can image how hard this could be when you just use CString, or string classes.
See detail about regular expression here.
DocProject, a document generate tool
- VisualStudio 2005 or 2008;
- Sandcastle
- Help 1.x
- Help 2.x (optional)
- DocProject
Make your "Hello World" DocProject
- Create a C# project, do some comments in the codes, check the "XML Documentation File" in project properties "Build" tab.
- Create a DocProject project, just follow the wizard, you can easily to setup it;
- Compile the projects, this may take some time, just be patient.
- After compile finished, you get your document. Yeah~~
Others
After do these, you may get a compile warning 1591, because you are not comment all the classes, functions, etc. Your can suppress this warning in project properties "Build" tab.