I haven't sent any code for a long time. I want to send some C # code today.

Source: Internet
Author: User
// 2005-3-17 // <summary> // progress information processing Commission // </Summary> /// <Param name = "completedstep" type = "int"> Number of completed steps </param> // <Param name = "totalstep" type = "int"> total number of steps </param> Public Delegate void progresshandler (INT completedstep, int totalstep ); /// <summary> /// universal function set /// </Summary> public class yyfcommon {// <summary> /// send data to the specified URL using the POST method, this function does not handle errors /// </Summary> /// <Param name = "strurl"> URL string </PA Ram> /// <Param name = "bytsend"> binary data to be sent </param> /// <Param name = "sendprogress"> process the progress of data sending </param> /// <Param name = "acceptprogress"> progress when receiving data </param> /// <returns> received binary data </returns> Public static byte [] httppostdata (string strurl, byte [] bytsend, progresshandler sendprogress, progresshandler acceptprogress) {// send data system. net. httpwebrequest myreq = (system. net. httpwebrequest) system. net. webrequest. CRES Ate (strurl); myreq. method = "Post"; system. Io. Stream mystream = myreq. getrequeststream (); int icount = 0; If (sendprogress! = NULL) sendprogress (0, bytsend. length); While (icount <bytsend. length) {If (icount + 1024> bytsend. length) {mystream. write (bytsend, icount, bytsend. length-icount); icount = bytsend. length;} else {mystream. write (bytsend, icount, 1024); icount + = 1024;} If (sendprogress! = NULL) sendprogress (icount, bytsend. Length);} // whileif (sendprogress! = NULL) sendprogress (bytsend. length, bytsend. length); mystream. close (); // accept the data system. net. httpwebresponse Myres = NULL; Myres = myreq. getresponse () as system. net. httpwebresponse; mystream = Myres. getresponsestream (); system. io. memorystream mybuf = new system. io. memorystream (1024); byte [] bytbuf = new byte [1024]; int contentlength = (INT) Myres. contentlength; int acceptlength = 0; If (acceptprogress! = NULL) acceptprogress (0, contentlength); While (true) {int ilen = mystream. read (bytbuf, 0,1024); If (ilen = 0) break; mybuf. write (bytbuf, 0, ilen); acceptlength + = ilen; If (acceptlength> contentlength) contentlength = acceptlength; If (acceptprogress! = NULL) acceptprogress (acceptlength, contentlength);} // whileif (acceptprogress! = NULL) acceptprogress (acceptlength, contentlength); mystream. close (); Myres. close (); myreq. abort (); byte [] bytreturn = mybuf. toarray (); mybuf. close (); Return bytreturn;} // public static byte [] httppostdata () /// <summary> /// modify the string according to the data source parameter saved in the list /// </Summary> /// <Param name = "strtext"> for processing original string </param> /// <Param name = "strhead"> tagged header string </param> /// <Param name = "strend"> tagged tail string </param> // <Param name = "Myke YS "> Save the list of all parameters </param> // <returns> processed string </returns> Public static string fixvariablestring (string strtext, string strhead, string strend, system. collections. hashtable mykeys) {// exit the function if (strtext = NULL | strhead = NULL | strend = NULL | strhead. length = 0 | strend. length = 0 | strtext. length = 0 | mykeys = NULL | mykeys. count = 0) return strtext; int Index = strtext. indexof (St Rhead); // exit the function if (index <0) return strtext; string strkey; int index2; int lastindex = 0; system. text. stringbuilder mystr = new system. text. stringbuilder (); do {// find the sub-string with the "[content]" style // if the "[" and "]" character pairs are not found, exit the loop index2 = strtext. indexof (strend, index + 1); If (index2> index) {// if the "[" symbol is followed by the "]" symbol, the "[]" character pair // corrects the search result to ensure that "[]" character pairs do not contain characters "[ "int index3 = index; do {Index = index3; index3 = Str Text. indexof (strhead, index3 + 1);} while (index3> index & index3 <index2); // obtain the character-to-pair substring, the sub-string is the parameter name // If the parameter name is valid, the parameter value is output to the output result // otherwise, no additional processing strkey = strtext is performed. substring (index + strhead. length, index2-index-strhead. length); If (mykeys. containskey (strkey) {If (lastindex <index) {mystr. append (strtext. substring (lastindex, index-lastindex);} mystr. append (mykeys [strkey] as string); Index = index 2 + strend. length; lastindex = index;} elseindex = index2 + strend. length;} else {break;} while (index >=0 & index <strtext. length); // Add the remaining string if (lastindex <strtext. length) mystr. append (strtext. substring (lastindex); Return mystr. tostring ();} // end of function: fixvariablestring /// <summary> /// calculate the drag and drop control rectangle of the specified rectangle /// </Summary> /// <Param name = "myrect"> area of the primary rectangle </ param> // <Param name = "dragrectsize"> Drag the rectangle </param> /// <Param name = "innerdragrect"> whether the rectangle is inside the main rectangle, if the value is false, drag the rectangle to turn out. </param> /// <remarks> // drag the rectangle to display the user interface, there are a total of eight control points between the four vertices in a rectangle and the middle point in the border. // you can drag the eight control points to change the position and size of the rectangle, these control points can be located inside the area, /// you can also drag eight rectangles to the outside of the area, numbers from 0 to 7, respectively. // <PRE> // drag the rectangle inside. // ┌ ── ─ ┐ // │ ■ 0 1 ■ 2 ■ │ // │ ■ 7 3 ■ │ /// │ // │ ■ 6 5 ■ 4 ■ │ // └ ── ─ /// /// Drag a rectangle to the canvas // ■ // ┌ ── ─ ── ┐ // │ 0 1 2 │ // /│ // ■ │ 7 3 │ ■ // │ /// │ // │ 6 5 4 │ // └ ── ─ ┘ // ■ // </PRE> // </remarks> // <returns> drag the array of the rectangle, there are 8 elements </returns> Public static system. drawing. rectangle [] getdragrects (system. drawing. rectangle myrect, int dragrectsize, bool innerdragrect) {system. drawing. rectangle [] dragrects = new system. dra Wing. rectangle [8]; If (innerdragrect) {dragrects [0] = new system. drawing. rectangle (myrect. x, myrect. y, dragrectsize, dragrectsize); dragrects [1] = new system. drawing. rectangle (myrect. X + (INT) (myrect. width-dragrectsize)/2), myrect. y, dragrectsize, dragrectsize); dragrects [2] = new system. drawing. rectangle (myrect. right-dragrectsize, myrect. y, dragrectsize, dragrectsize); dragrects [3] = New system. drawing. rectangle (myrect. right-dragrectsize, myrect. Y + (INT) (myrect. height-dragrectsize)/2), dragrectsize, dragrectsize); dragrects [4] = new system. drawing. rectangle (myrect. right-dragrectsize, myrect. bottom-dragrectsize, dragrectsize, dragrectsize); dragrects [5] = new system. drawing. rectangle (myrect. X + (INT) (myrect. width-dragrectsize)/2), myrect. bottom-drag Rectsize, dragrectsize, dragrectsize); dragrects [6] = new system. drawing. rectangle (myrect. x, myrect. bottom-dragrectsize, dragrectsize, dragrectsize); dragrects [7] = new system. drawing. rectangle (myrect. x, myrect. Y + (INT) (myrect. height-dragrectsize)/2), dragrectsize, dragrectsize);} else {dragrects [0] = new system. drawing. rectangle (myrect. x-dragrectsize, myrect. y-dragrectsize, Dragrectsize, dragrectsize); dragrects [1] = new system. drawing. rectangle (myrect. X + (INT) (myrect. width-dragrectsize)/2), myrect. y-dragrectsize, dragrectsize, dragrectsize); dragrects [2] = new system. drawing. rectangle (myrect. right, myrect. y-dragrectsize, dragrectsize, dragrectsize); dragrects [3] = new system. drawing. rectangle (myrect. right, myrect. Y + (INT) (myrect. height-drag Rectsize)/2), dragrectsize, dragrectsize); dragrects [4] = new system. drawing. rectangle (myrect. right, myrect. bottom, dragrectsize, dragrectsize); dragrects [5] = new system. drawing. rectangle (myrect. X + (INT) (myrect. width-dragrectsize)/2), myrect. bottom, dragrectsize, dragrectsize); dragrects [6] = new system. drawing. rectangle (myrect. x-dragrectsize, myrect. bottom, dragrectsize, drag Rectsize); dragrects [7] = new system. drawing. rectangle (myrect. x-dragrectsize, myrect. Y + (INT) (myrect. height-dragrectsize)/2), dragrectsize, dragrectsize);} return dragrects ;} /// <summary> /// calculate the cursor position on the drag rectangle /// </Summary> /// <remarks> /// set the cursor as follows // Northwest China -Southeast, north, south, and Northeast-Southwest China // ■ // ┌ ── ─ ┐ // │ 0 1 2 │ // /│ // ■ │ 7 west-south 3 │ ■ west-south // │ // /│ // │ 6 5 4 │ // └ ── ┘ // ■ // Northeast-southwest-northwest-Southeast // </remarks> /// <Param name = "Index"> drag the sequence number of the rectangle, from 0 to 7 </param> /// <returns> cursor object. If the serial number is less than 0 or greater than 7, an empty reference is returned. </returns> Public static system. windows. forms. cursor getdragrectcursor (INT index) {Switch (INDEX) {Case 0: return system. windows. forms. cursors. sizenwse; Case 1: return system. windows. forms. cursors. sizens; Case 2: return system. windows. forms. cursors. sizenesw; c ASE 3: return system. windows. forms. cursors. sizewe; Case 4: return system. windows. forms. cursors. sizenwse; Case 5: return system. windows. forms. cursors. sizens; Case 6: return system. windows. forms. cursors. sizenesw; Case 7: return system. windows. forms. cursors. sizewe;} return NULL; }}/// <summary> // operating system clipboard processing module, the provided method is a static function // </Summary> /// <example> // example of using this class in C, obtain plain text data from the operating system clipboard //// determine whether the operating system clipboard stores plain text data /// If (clipboardhandler. cangettext () /// {//// return the obtained plain text data // return clipboardhandler. gettextfromclipboard (); //} // set plain text data to the operating system clipboard /// string strtext = "plain text data to be set "; /// clipboardhandler. settexttoclipboard (strtext ); /// </example> public class clipboardhandler {// <summary> // whether the text can be obtained from the operating system clipboard /// </Summary> /// <returns> true: You can obtain text from the operating system clipboard, false not allowed </returns> Public static bool cangettext () {// clipb Oard. getdataobject may throw an exception... try {system. Windows. Forms. idataobject DATA = system. Windows. Forms. clipboard. getdataobject (); return data! = NULL & data. getdatapresent (system. windows. forms. dataformats. text) ;}catch (exception e) {return false ;}} ////// <summary> //// whether text can be set to the operating system clipboard //// </Summary> //// <returns> </returns> // public static bool cansettext () // {// return true; //}/// <summary> /// set text data to the operating system clipboard /// </Summary> /// <Param name = "strtext"> text data </param> // <returns> whether the operation is successful </returns> Public static bool settexttoclipboard (string strtex T) {If (strtext! = NULL & strtext. length> 0) {try {system. windows. forms. dataobject = new system. windows. forms. dataobject (); dataobject. setdata (system. windows. forms. dataformats. unicodetext, true, strtext); system. windows. forms. clipboard. setdataobject (dataobject, true); Return true;} catch {}} return false ;} /// <summary> /// obtain the text from the operating system clipboard /// </Summary> /// <returns>, if the operation fails, an empty object </returns> Public static string gettextfromclipboard () {try {system. windows. forms. idataobject DATA = system. windows. forms. clipboard. getdataobject (); If (data. getdatapresent (system. windows. forms. dataformats. unicodetext) {string strtext = (string) data. getdata (system. windows. forms. dataformats. unicodetext); Return strtext ;}} catch {} return NULL ;}}

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.