First, minimize windows
Click "X" or "Alt F4", minimize windows,
Such as:
Protected Override Void WndProc (Ref Message M)
{
Const int WM_SYSCOMMAND = 0x0112;
Const int sc_close = 0xf060;
IF (M.MSG == WM_SYSCOMMAND & & (INT) m.wparam == sc_close)
{
// User Clicked Close Button
this.windowState = formwindowstate.minimized;
Return;
}
Base.WndProc (Ref M);
}
Second, how to make the foreach loop faster
Foreach is a ready-made statement that makes a simple enumeration and processing of elements in the collection, as shown in the following example:
Using system;
Using system.collections;
Namespace looptest
{
Class class1
{
Static void main (string [] args)
{
// Create an ArrayList of Strings
Arraylist array = new arraylist ();
Array.Add ("Marty");
Array.Add ("Bill");
Array.Add ("George");
// Print The Value of Every Item
FOREACH (String Item in Array)
{
Console.writeLine (item);
}
}
}
You can use the foreach statement in each of the set of Ienumerable interfaces. If you want to know more foreach usage, you can view the C # Language Specification in the .NET Framework SDK document.
When compiling, the C # editor converts each Foreach area. IEnumerator Enumerator = array.getenumerator ();
Try
{
String item;
While (enumerator.movenext ())
{
Item = (string) enumerator.current;
Console.writeLine (item);
}
}
Finally
{
Idisposable d = enumerator as idisposable;
IF (d! = null) d.dispose ();
}
This shows that in the background, Foreach's management will bring you some additional code that increases system overhead.
Third, save pictures to an XML file
In WinForm's resource file, non-text content such as porturebox's image property is converted into text, which is implemented by serialization.
example://
Using system.Runtime.Serialization.formatters.soap;
Stream Stream = New FileStream ("E: //Image.xml", FileMode.create, FileAccess.write, Fileshare.none;
SOAPFORMATTER F = New soapFormatter ();
Image img = image.fromfile ("e: //image.bmp");
F.Serialize (Stream, IMG);
stream.close ();
Fourth, shield Ctrl-V
The TextBox control in WinForm does not block the Ctrl-V clipboard paste action, if you need an input box, you don't want the user to paste the contents of the clipboard, you can use the RichTextBox control, and shield the Ctrl-V key in KeyDown ,example:
Private void RichtextBox1_keydown (Object Sender, System.Windows E)
{
IF (E.Control && E.Keycode == Keys.v)
e.handled = true;
}