I haven't sent a code for a long time, come today, I will send some C # code.

xiaoxiao2021-03-06  15

// Nanjing thousands of miles 2005-3-17

///

// Progress information processing commission

///

/// The number of steps that have been completed

/// The total number of steps

Public Delegate Void ProgressHandler (Int CompletedStep, Int Totalstep);

///

/// universal function collection

///

Public Class Yyfcommon

{

///

// / This function does not perform errors to send data to the specified URL using the POST method.

///

/// URL string

/// Binary data to send

/// progress processing when sending data

/// progress processing when receiving data

/// Accepted binary data

Public static botty [] httppostdata

String Strurl,

Byte [] Bytsend,

ProgressHandler SendProgress,

ProgressHandler AcceptProgress

{

// send data

System.net.httpwebrequest myreq = (system.net.httpwebrequest) system.net.WebRequest.create (Strurl);

MyReq.Method = "post";

System.io.stream mystream = myreq.getRequestStream ();

Int iCount = 0;

IF (sendProgress! = null)

SendProgress (0, Bytsend.Length);

While (ICOUNT

{

IF (ICOUNT 1024> ByTsend.Length)

{

MyStream.write (Bytsend, ICOUNT, BYTSEND.LENGTH - ICOUNT);

iCount = bytesend.length;

}

Else

{

MyStream.write (Bytsend, Icount, 1024);

ICOUNT = 1024;

}

IF (sendProgress! = null)

SendProgress (iCount, ByTsend.Length);

} // while

IF (sendProgress! = null)

SendProgress (Bytsend.Length, Bytsend.Length);

MyStream.close ();

// Accept 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;

an (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 = AcceptLect "

an (acceptprogress! = null)

Acceptprogress (AcceptLength, ContentLength);

} // while

an (acceptprogress! = null)

Acceptprogress (AcceptLength, ContentLength);

MyStream.close ();

MYRES.CLOSE ();

MyReq.abort ();

BYTE [] BYTRETURN = mybuf.toArray ();

Mybuf.close ();

Return BytreTurn;

} // public static Byte [] httppostdata ()

///

// / According to the data source parameter of the saved in a list

///

/// Original string

/// tagged head string

/// tag tail string

/// Save all parameters list

/// After processed strings

Public Static String fixvariableString

(String Strtext,

String strhead,

String strend,

System.collections.hashtable mykeys

{

// If the original string is invalid or there is no available parameters to 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;

INDEX = strText.indexof (strhead);

// If the original string has no variable tag, 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 a sub-string with "[Content]" style

// If you don't find the character pair of ["and"] "to exit the loop

Index2 = Strtext.indexof (Strend, INDEX 1);

IF (Index2> Index)

{

// If the "]" symbol appears after the "[" symbol, "[]" characters are

// Find the result to ensure that "[]" characters do not appear "[" ["

INT index3 = index;

DO

{

Index = index3;

Index3 = Strtext.indexof (Strhead, Index3 1);

WHILE (Index3> index && index3

// Get the slave string of the character pair, the sub string is the parameter name.

// If this parameter name is valid, the parameter value is output to the output result.

/ / Otherwise no additional processing

strkey = strText.Substring (Index strhead.length, index2 - index - strhead.length);

IF (myKeys.containskey)

{

LastIndex

{

MyStr.Append (Strtext.Substring (LastIndex, INDEX - LastIndex);

}

MyStr.Append (myKeys [strkey] as string;

INDEX = Index2 Strend.Length;

LastIndex = Index;

}

Else

INDEX = Index2 Strend.Length;

}

Else

{

Break;

}

WHILE (INDEX> = 0 && index

// Add the remaining strings after processing

LastIndex

MyStr.Append (Strtext.Substring (lastIndex));

Return myStr.toT7tring ();

} // end of function: fixvariableString

///

/// calculate the drag and drop control rectangle of the specified rectangle

///

/// Main rectangular area

/// Drag and drop rectangle

/// Drag and drop in the main rectangle inside, if false drags the rectangular valve

/// /// Drag and drop rectangle is mainly used to have a user-participated graphical user interface, with 8 control points in the four top points and border intermediate points of a rectangular area.

/// The user uses a mouse drag operation to drag these 8 control points to change the position and size of the rectangular area, which can be inside the area area,

/// can also be 8 in the rectangular area, the drag rectangle is 8, respectively from 0 to 7, respectively.

///

/// Drag and drop rectangle

/// - --───────────────

/// │ ■ 0 1 ■ 2 ■ │

/// │ │

/// │ │

/// │ │

/// │ │

/// │ ■ 7 3 ■ │

/// │ │

/// │ │

/// │ │

/// │ │

/// │ ■ 6 5 ■ 4 ■ │

/// - --───────────────

///

/// external drag rectangle

///

/// ■ ■ ■

/// - ────────────────

/// │0 1 2│

/// │ │

/// │ │

/// │ │

/// │ │

/// ■ │7 3│ ■

/// │ │

/// │ │

/// │ │

/// │ │

/// │6 5 4 │

/// - ────────────────

/// ■ ■ ■

///

///

/// array of dragging rectangles, 8 elements

Public static system.drawing.rectangle [] getDragRects (System.drawing.Rectangle MyRect, int DragRectsize, Bool InnerDragRect)

{

System.drawing.Rectangle [] DRAGRECTS = New System.drawing.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)) / 2) / 2) / 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)) / 2) / 2) / 2), MyRect.Bottom - DragRectSize, 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.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) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT) ((INT), 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, DragRectsize);

DragRects [7] = New System.drawing.Rectangle (MyRect.x - DragRectSize, MyRect.height - DragRectsize / 2) / 2), DragRectSize, DragRectsize;

}

Return DragRects;

}

///

/ / / Calculate the mouse cursor position on the rectangle

///

///

/// The mouse setting is as follows

/// Northwest - Northeast South Northeast - Southwest

/// ■ ■ ■

/// - ────────────────

/// │0 1 2│

/// │ │

/// │ │

/// │ │

/// │ │

/// ■ │7 West - South 3│ ■ West - South

/// │ │

/// │ │

/// │ │

/// │ │

/// │6 5 4 │

/// - ────────────────

/// ■ ■ ■

/// Northeast - Northwestern South China Northwest - Southeast

///

/// Drag and drop the number of rectangles from 0 to 7

/// Mouse cursor object, if the serial number is less than 0 or greater than 7, return to the empty reference

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.siznesw;

Case 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.siznesw;

Case 7:

Return system.windows.Forms.cursors.sizewe;

}

Return NULL;

}

}

///

/// Operating the system shearing board processing module, the method provided is a static function

///

///

/// C # language uses this class example, get plain text data from the operating system shear board

// / / Judgment whether the operating system shear board saves plain text data

/// if (clipboardhandler.cangetText ())

/// {

/ / / / Return to the obtained plain text data

/// Return ClipboardHandler.getTextFromClipboard ();

///}

///

// / Set plain text data to the operating system shear board

/// String Strtext = "Plain text data to be set";

/// ClipboardHandler.SettextToclipboard (Strtext);

///

Public Class ClipboardHandler

{

///

/ / Whether you can get text from the operating system shear board

///

/// TRUE can get text from the operating system shear board, FALSE is not

Public Static Bool CangetText ()

{

// clipboard.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;

}

}

//

// ///

/ / / Can you set the text to the operating system shear board

// ///

/////

// public static bool can settext ()

// {

// Return True;

//}

///

// / Set text data to the operating system shear board

///

/// Text Data

/// Whether the operation is successful

Public Static Bool SetTextToclipboard (String Strtext)

{

IF (Strtext! = Null && Strtext.length> 0)

{

Try

{

System.windows.Forms.DataObject 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;

}

///

/// Get text from the operating system shear board

///

/// returns to the empty object if the operation fails.

Public static string getTextFromClipboard ()

{

Try

{

System.windows.forms.idataObject data = system.windows.forms.clipboard.getdataObject ();

IF (data.getdatapresent (system.windows.forms.dataFormats.Unicodetext))

{

String stratext = (string) data.getdata (system.windows.forms.dataFormats.Unicodetext);

Return strText;

}

}

Catch

{}

Return NULL;

}

}

转载请注明原文地址:https://www.9cbs.com/read-46202.html

New Post(0)