主题:[原创]初学者必看!!!小知识点总结~~~(一)
1. 获取“我的文档”等一些系统文件夹路径
MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
2. 确定当前运行的系统
OperatingSystem os = Environment.OSVersion;
MessageBox.Show(os.Version.ToString());
MessageBox.Show(os.Platform.ToString());
3. 模拟触发buttonclick事件
button1.PerformClick();
4. 创建一个可改变大小没有标题栏的窗体
form1.Test = string.Empty;
form1.ControlBox = false;
5. 如何在.NET的Windows窗体上启用XP主题集?(How to use XP Themes with Windows Forms using the .NET?)
确认你的控件中FlatStyle属性已经修改为System,再修改Main方法。
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}
6. 为一个窗体设置一个默认按钮
form1.AcceptButton = button1;
7. 为一个窗体设置一个取消按钮
form1.CancelButton = button1;
8. 用现有可用字体绑定到ComboBox控件
comboBox1.Items.AddRange(FontFamily.Families);
9. 清理语句
private bool Disposed;
private void Disposed()
{
if(Disposed)
return;
Disposed = true;
GC.SuppressFinalize(this);
}
10. 声明索引属性
public String this[String name]
{
get
{
retrun (String) lookuptable[name];
}
}
11. 访问索引属性
String s = Request.QueryString["Name"];
String value = Request.Cookies["Key"];
12. 声明简单属性
public string name
{
get
{
....
return......;
}
set
{
.......=value;
}
}
13. 声明和使用枚举
// Declare the Enumeration
public enum MessageSize
{
Small = 0,
Medium =1,
Large = 2
}
// Creat a Field or Property
public MessageSize msgsize;
// Assign to the property using the Enumeration values
msgsize = Small;
14. 枚举集合
foreach (String s in coll) {
}
15. 声明和使用方法
// Declare a void return function
void voidfunction() {
.......
}
// Declare a function tha retruns a value
String stirngfunction() {
.............
return (String) val;
}
// Declare a function that takes and returns values
String parmfunction(String a , String b) {
.........
return (String) (a + b);
}
// Use the Functions
voidfunction();
String s1 = stringfunction();
String s2 = parmfunction("Hello","World!");
16. 自定义特性
// Stand-alone attribute
[STAThread]
// Attribute with parameters
[DllImport("ADVAPI32.DLL"]
// Attribute with named parameters
[DllImport("KERNEL32.DLL",CharSet = CharSet.Auto)]
17. 数组
String[] a = new String[3];
a[0] ="1";
a[1] ="2";
a[2] = "3";
String[][] a = new String[3][3];
a[0][0] = "1";
a[1][0] = "2";
a[2][0] = "3";
18. 初始化
String s= "Hello , World!";
int i = 2;
double[] a = {3.00,4.00,5.00};
19. If 语句
if(Request .QueryString != null) {
......
}
20. Case语句
switch (FirstName) {
case "John" :
......
break;
case"Paul" :
..........
break;
case"Ringo" :
.........
break;
dafault :
...........
break;
}
MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
2. 确定当前运行的系统
OperatingSystem os = Environment.OSVersion;
MessageBox.Show(os.Version.ToString());
MessageBox.Show(os.Platform.ToString());
3. 模拟触发buttonclick事件
button1.PerformClick();
4. 创建一个可改变大小没有标题栏的窗体
form1.Test = string.Empty;
form1.ControlBox = false;
5. 如何在.NET的Windows窗体上启用XP主题集?(How to use XP Themes with Windows Forms using the .NET?)
确认你的控件中FlatStyle属性已经修改为System,再修改Main方法。
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}
6. 为一个窗体设置一个默认按钮
form1.AcceptButton = button1;
7. 为一个窗体设置一个取消按钮
form1.CancelButton = button1;
8. 用现有可用字体绑定到ComboBox控件
comboBox1.Items.AddRange(FontFamily.Families);
9. 清理语句
private bool Disposed;
private void Disposed()
{
if(Disposed)
return;
Disposed = true;
GC.SuppressFinalize(this);
}
10. 声明索引属性
public String this[String name]
{
get
{
retrun (String) lookuptable[name];
}
}
11. 访问索引属性
String s = Request.QueryString["Name"];
String value = Request.Cookies["Key"];
12. 声明简单属性
public string name
{
get
{
....
return......;
}
set
{
.......=value;
}
}
13. 声明和使用枚举
// Declare the Enumeration
public enum MessageSize
{
Small = 0,
Medium =1,
Large = 2
}
// Creat a Field or Property
public MessageSize msgsize;
// Assign to the property using the Enumeration values
msgsize = Small;
14. 枚举集合
foreach (String s in coll) {
}
15. 声明和使用方法
// Declare a void return function
void voidfunction() {
.......
}
// Declare a function tha retruns a value
String stirngfunction() {
.............
return (String) val;
}
// Declare a function that takes and returns values
String parmfunction(String a , String b) {
.........
return (String) (a + b);
}
// Use the Functions
voidfunction();
String s1 = stringfunction();
String s2 = parmfunction("Hello","World!");
16. 自定义特性
// Stand-alone attribute
[STAThread]
// Attribute with parameters
[DllImport("ADVAPI32.DLL"]
// Attribute with named parameters
[DllImport("KERNEL32.DLL",CharSet = CharSet.Auto)]
17. 数组
String[] a = new String[3];
a[0] ="1";
a[1] ="2";
a[2] = "3";
String[][] a = new String[3][3];
a[0][0] = "1";
a[1][0] = "2";
a[2][0] = "3";
18. 初始化
String s= "Hello , World!";
int i = 2;
double[] a = {3.00,4.00,5.00};
19. If 语句
if(Request .QueryString != null) {
......
}
20. Case语句
switch (FirstName) {
case "John" :
......
break;
case"Paul" :
..........
break;
case"Ringo" :
.........
break;
dafault :
...........
break;
}