I.. NET Framework
1. How to obtain the system folder
Use the getfolderpath method of the system. enviment class. For example:
Environment. getfolderpath (environment. specialfolder. Personal)
2. How to obtain the path of the EXE file being executed
1) Use the executablepath attribute of the application class
2) system. reflection. Assembly. getexecutingassembly (). Location
3. How to check the operating system version
Use the osversion attribute of enviment, for example:
Operatingsystem OS = environment. osversion;
MessageBox. Show (OS. version. tostring ());
MessageBox. Show (OS. Platform. tostring ());
4. How to obtain the file name part based on the complete file name,
Use the system. Io. Path class method getfilename or getfilenamewithoutextension
5. How to get the file extension by the full name of the file
Use System. Io. Path. getextension static method
7. How to obtain the User Name of the current computer, whether the computer is connected to the Internet, how many monitors, the domain, and the mouse keys
Use the static attributes of the system. Windows. Forms. systeminformation class
8. What is the role of modifying the [stathread] feature of the main method?
Current Program Run in single thread mode
9. How to read the contents of a CSV file
You can create a link to the CSV file through odbcconnection. The format of the link string is: "driver = {Microsoft text Driver (*. txt ;*. CSV)}; DBQ = "+ CVS folder path +" extensions = ASC, CSV, tab, txt; persist Security info = false ";
After creating a connection, you can use dataadapter to access CSV files.
10. How to obtain disk overhead information, Code The snippet is as follows. It mainly calls the getdiskfreespaceex external method in kernel32.dll.
Public sealed class driveinfo
{
[Dllimport ("kernel32.dll", entrypoint = "getdiskfreespaceexa")]
Private Static extern long getdiskfreespaceex (string lpdirectoryname,
Out long lpfreebytesavailabletocaller,
Out long lptotalnumberofbytes,
Out long lptotalnumberoffreebytes );
Public static long getinfo (string drive, out long available, out long total, out long free)
{
Return getdiskfreespaceex (drive, out available, out total, out free );
}
Public static driveinfosystem getinfo (string drive)
{
Long result, available, total, free;
Result = getdiskfreespaceex (drive, out available, out total, out free );
Return new driveinfosystem (drive, result, available, total, free );
}
}
Public struct driveinfosystem
{
Public readonly string drive;
Public readonly long result;
Public readonly long available;
Public readonly long total;
Public readonly long free;
Public driveinfosystem (string drive, long result, long available, long total, long free)
{
This. Drive = drive;
This. Result = result;
This. Available = available;
This. Total = total;
This. Free = free;
}
}
You can use
11. How to obtain the index location of case-insensitive substring
1) convert the two strings to lowercase and use the indexof method of the string:
String strparent = "The codeproject site is very informative .";
String strchild = "codeproject ";
// The line below will return-1 when expected is 4.
Int I = strparent. indexof (strchild );
// The line below will return proper index
Int J = strparent. tolower (). indexof (strchild. tolower ());
2)
Using system. Globalization;
String strparent = "The codeproject site is very informative .";
String strchild = "codeproject ";
// We create a object of compareinfo class for a neutral culture or a culture insensitive object
Compareinfo compare = cultureinfo. invariantculture. compareinfo;
Int I = compare. indexof (strparent, strchild, compareoptions. ignorecase );
II
1. What is a replication constructor?
We know that constructor is a special method used to initialize the instance we want to create. Usually we need to assign an Instance value to another variable C # just assign the reference value to a new variable which is essentially a reference to the same variable, so how can we create a new variable while assigning values, not just assigning values to instance references? We can use the copy constructor.
We can create a constructor for a class that uses only one parameter of this type, for example:
Public student (Student)
{
This. Name = student. Name;
}
With the above constructor, we can copy a new instance value instead of assigning values to the same referenced instance.
Class student
{
Private string name;
Public student (string name)
{
This. Name = Name;
}
Public student (Student)
{
This. Name = student. Name;
}
Public string name
{
Get
{
Return name;
}
Set
{
Name = value;
}
}
}
Class final
{
Static void main ()
{
Student = new student ("");
Student newstudent = new student (student );
Student. Name = "B ";
System. Console. writeline ("the new student's name is {0}", newstudent. Name );
}
}
The new student's name is.
2. What is a read-only constant?
It is a static read-only variable, which is usually assigned a value in the static constructor.
Class numbers
{
Public readonly int m;
Public static readonly int N;
Public numbers (int x)
{
M = X;
}
Static numbers ()
{
N = 100;
}
} // Where N is a read-only constant, there is only one value for all instances of this class, and m is different according to the instance
Iii. vs. Net ide
3. How to change the region color
You can set the font and color of the tool to foldable text.
Iv. winform
1. How do I disable winform from displaying the title bar?
Set the text attribute of form to an empty string and the controlbox attribute to false.
Form1.text = string. empty;
Form1.controlbox = false;
2. How to make windows form use the XP style
3. How to disable form display on the toolbar
Set the showintaskbar attribute of form to false.
4. How to enable the program to open the default mail program with some parameters for users to start writing emails
1) For web programs:
<A href = "mailto: email@address1.com, email@address2.com? Cc = email@address3.com & subject = Hello & Body = Happy New Year "> some text </a>
2) For Windows programs, you need to use the system. Diagnostics. Process class. How to Create a prompt window similar to msn
Process = new process ();
Process. startinfo. filename = "mailto: email@address1.com, email@address2.com? Subject = Hello & CC = email@address3.com
& BCC = email@address4.com & Body = Happy New Year ";
Process. Start ();
5. You need to obtain the screen size through the screen. getworkingarea (this). Width (height) attribute, and then use a timer to change the position of the window according to the time.
5. Button Control
1. How to set the default button of form (that is, the button triggered when you press enter on form)
You can set the form's acceptbutton attribute: form1.acceptbutton = button1;
2. How to set the form cancel button (that is, the button triggered when the user presses the ESC key)
You can set the cancelbutton attribute of form: form1.cancelbutton = buttonc;
3. How to trigger a button click event through a program
Button1.w.mclick
6. Combo box
1. How to fill the combo box with an optional font
Combobox1.items. addrange (fontfamily. families );
VII. textbox
1. how to disable the default context menu of Textbox (right-click menu)
Textbox1.contextmenu = new contextmenu ();
4. How to put the focus at the end of the textbox text when the textbox gets the focus
Textbox1.selectionstart = textbox1.text. length;
. Oops a more elegant method is to use system. indexof method of the compareinfo class under the globalization namespace: driveinfosystem info = driveinfo. getinfo ("C:"); to get the overhead of the specified Disk