(1) Immediately close the entire application, will not wait for the current process to end, equivalent to the Task Manager in the direct shutdown process
System.Environment.Exit (0);
(2) WPF opens the browser and jumps to the fixed URL
Process proc = new System.Diagnostics.Process ();
Proc. Startinfo.filename = "http://www.baidu.com";
Proc. Start ();
(3) WinForm session to keep the site login status
Jobject javascript = null; Username=test&password=fantao string postdata = "Username=" +datauserinfo.name + "&password=" + Data
Userinfo.password;//post parameters and values are written in postdate byte[] ByteArray = Encoding.Default.GetBytes (postdata); String url = "Http://baidut.com/getservers?";
Post to the Web site HttpWebRequest webRequest = (HttpWebRequest) webrequest.create (new Uri (URL));
Webrequest.method = "POST";
Webrequest.contenttype = "application/x-www-form-urlencoded";
Webrequest.contentlength = Bytearray.length;
Webrequest.cookiecontainer = Datauserinfo.mycookie; Cookiecontainer cookie = webrequest.cookiecontainer;//If no cookie is used, delete the Stream newstream = webrequest.ge
Trequeststream ();
Newstream.write (ByteArray, 0, bytearray.length);
Newstream.close (); Receive return information: httpwebresponse response = (HTTPWEBRESPONSE) Webrequest.getresponse (); WebHeaderCollection mywebheadercollection =response. Headers;//gets the session StreamReader php = new StreamReader (response.
GetResponseStream (), encoding.default); String SL = Response.
Headers.get ("Set-cookie"); String message = php.
ReadToEnd ();
JavaScript = (jobject) jsonconvert.deserializeobject (message); if (javascript["status"). ToString () = = "n")//{//String s = javascript["info"]. ToString ()//Back error message//}
4.HashTable method of value and key
foreach (DictionaryEntry de in Htservervsname)//htservervsname is hashtable
{
string sed = de. Key.tostring ();
String seds = de. Value.tostring ();
}
5. Manipulating the DataTable in the dataset
DataTable dt = new DataTable ("myDT");
DataSet ds = new DataSet ("myDS");
Ds. Tables.add (DT);//Add table to the library, how, simple, hehe
//ds. tables["myDT"]. rows[2]["Name" = "language";//Assign a value//ds to a record in a field in a table
. tables["myDT"] finds the table with the
if (DS). Tables.contains ("myDT"))
{
foreach (DataRow temprow in DS). tables["myDT"]. Rows)
{
if ("IP" = temprow["Server"]. ToString ())
{
//traverse fetch data
}
}
}
6. Use memory sharing for interprocess communication, convenient and quick.
Enables a single program to start and open programs and pallet operations that are started
7. WPF MessageBox with selection buttons
ButtonBase button = this. Template.findname ("Part_closebutton", this) as ButtonBase;
if (button!= null)
{
button. Click = = delegate//Anonymous delegate
{
Messageboxresult dr = MessageBox.Show ("You are deleting this server entry.") \ n \ nyou sure you want to delete this server entry? "," hint ", messageboxbutton.okcancel);
if (dr = = Messageboxresult.ok)
{
//Get the parent TabControl
TabControl TC = helper.findparentcontrol< Tabcontrol> (this);
if (TC = null) return;
Remove this tabitem from the parent TabControl
TC. Removetabitem (this);}}
8. Transaction delegation
A WPF application starts with two threads: one for rendering and the other for managing the UI. The rendering thread actually hides in the background, while the UI thread receives input, handles events, draws the screen, and runs the application code. The UI thread queues work items in an object named dispatcher. Dispatcher selects work items according to priority and runs each work item until completed. The Dispatcher class provides two ways to register work items: Invoke and BeginInvoke. Both of these methods schedule a delegate to be executed. Invoke is a synchronous call, that is, it does not return until the UI thread actually finishes executing the delegate. BeginInvoke is called asynchronously and will be returned immediately.
Thread thread = new Thread (new ThreadStart (() =>
{
//Thread.Sleep (5000);
Dispatcher.invoke (New Action (() =>
{
//method Body
Fun ();
}), null);
});
Thread.Start ();
Thread t = new Thread (new ThreadStart (delegate
{
tb_test). Dispatcher.begininvoke (The new Action (delegate
{
tb_test). Text = "123";
}), null);
T.start ();
9.WPF background changes the font color of a TextBox or label or TextBlock
Textbox. foreground = new SolidColorBrush (colors.aliceblue); Fill the foreground with a solid brush
10.Listview vacuuming problem.
If the ListView data source comes from: listview.itemssource=list;
As long as the list is emptied, the ListView can be emptied;
If you use Listview.clear (), click the empty button multiple times to appear: The operation is invalid when ItemsSource is in use. Use Itemscontrol.itemssource to access and modify elements instead. This exception.
11.WPF animation After the completion of a potential line of events, LAMDA expression;
Storyboard SB = this. Resources["Storyboard"] as storyboard;
Sb.completed + = (s, a) =>
{
//work to be done
};
Sb. Begin ();
12.WPF Embedded WinForm Control
XMLNS:WFI = "Clr-namespace:system.windows.forms.integration;assembly=windowsformsintegration"
Access to control solutions in the main window in other custom classes in 13.WPF
For example, to find a StackPanel in a class, use the following method.
StackPanel SPI = Application.Current.MainWindow.FindName ("Itemstak") as StackPanel;
(Dictionary.add (Key, "123") and dictionary[key]= "123")
If the key is already in the Dictionary, then add will complain: an element with the same key already exists in Dictionary.
and Dictionary[key] will not error, no time to add, and sometimes modify the replacement, so it is more recommended to use this method, more secure, do not have to write an if judgment.