Implement color cursors and custom cursors in .NET WinForm

xiaoxiao2021-03-06  63

Using system.drawing; using system.componentmodel; using system.windows.form; using system.data;

Using system.Runtime.Interopservices; using system.reflection;

Namespace winform_test_guangbiao {///

/// This example The role of this example: /// The color cursor, animation cursor, and custom cursor are implemented in .NET. /// public class Form1: System.Windows.Forms.Form {[DllImport ( "user32.dll")] public static extern IntPtr LoadCursorFromFile (string fileName); [DllImport ( "user32.dll")] public Static Extern INTPTR SetCursor (INTPTR CURSORHANDLE); [DLLIMPORT ("User32.dll")] Public Static Extern Uint Destroycursor (INTPTR CURSORHANDLE);

///

/// The required designer variable. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();

THIS.TEXT = "Welcome to [Wonderful World of Meng Xian]: http://dotnet.aspx.cc/"; Cursor MyCursor = New Cursor (CURSOR.CURRENT.HANDLE); //dinosau2.ani is built for Windows . cursor: IntPtr colorCursorHandle = LoadCursorFromFile (@ "E: /WINDOWS/Cursors/dinosau2.ani"); myCursor.GetType () InvokeMember ( "handle", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField , null, mycursor, new object [] {colorcursorhandle}; this.cursor = mycursor;

// // Todo: Add any constructor code after INITIALIZEComponent call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method. /// private void initializecomponent () {/// Form1 // this.AutoscaleBasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (292, 273 ); This.name = "form1"; this.text = "form1"; this.load = new system.eventhandler (this.form1_load);} #ENDREGION

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.run (new form1 ());}

Private Void Form1_Load (Object Sender, System.Eventargs E) {

}}}

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

New Post(0)