When you click on "X" or "alt+f4", minimize the window,
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);
}
Ii. How to make the Foreach Loop run faster
foreach is a ready-made statement that simply enumerates and processes elements in a 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 collection that implements the IEnumerable interface. If you want to learn more about foreach usage, you can view the C # Language specification in the. NET Framework SDK documentation.
At compile time, the C # Editor transforms each foreach region. 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 means that in the background, foreach management will give your program extra code to increase the overhead of the system.
Third, save the picture to an XML file
WinForm's resource file, the PictureBox image property, and so on, are converted to text saving, which is accomplished by serialization (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 ();
Four, shielding Ctrl-v
The TextBox control in WinForm has no way to mask the ctrl-v clipboard paste action, if you need an input box, but you do not want the user to paste the contents of the Clipboard, you can use the RichTextBox control instead, and the CTRL-V key is masked in KeyDown, example:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service