Advertisement
fortsoft

LinkLabel

Mar 10th, 2023 (edited)
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | Source Code | 0 0
  1. /**
  2.  * This is open-source software licensed under the terms of the MIT License.
  3.  *
  4.  * Copyright (c) 2023 Petr Červinka - FortSoft <[email protected]>
  5.  * Copyright (c) 2012 Hamid Sadeghian
  6.  *
  7.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  8.  * of this software and associated documentation files (the "Software"), to deal
  9.  * in the Software without restriction, including without limitation the rights
  10.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11.  * copies of the Software, and to permit persons to whom the Software is
  12.  * furnished to do so, subject to the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice shall be included in all
  15.  * copies or substantial portions of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23.  * SOFTWARE.
  24.  **
  25.  * Version 1.1.0.0
  26.  */
  27.  
  28. using System;
  29. using System.Runtime.InteropServices;
  30.  
  31. namespace FortSoft.Controls {
  32.  
  33.     /// <summary>
  34.     /// Implements custom LinkLabel with proper system hand cursor.
  35.     /// </summary>
  36.     public class LinkLabel : System.Windows.Forms.LinkLabel {
  37.  
  38.         /// <summary>
  39.         /// Constant value found in the WinUser.h header file.
  40.         /// </summary>
  41.         public const int IDC_HAND = 0x7F89;
  42.  
  43.         /// <summary>
  44.         /// Import
  45.         /// </summary>
  46.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  47.         private static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
  48.  
  49.         /// <summary>
  50.         /// Proper system hand cursor.
  51.         /// </summary>
  52.         private static readonly System.Windows.Forms.Cursor SystemHandCursor =
  53.             new System.Windows.Forms.Cursor(LoadCursor(IntPtr.Zero, IDC_HAND));
  54.  
  55.         /// <summary>
  56.         /// Overriding OnMouseMove method. If the base class decided to show the
  57.         /// ugly hand cursor show the system hand cursor instead.
  58.         /// </summary>
  59.         protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) {
  60.             base.OnMouseMove(e);
  61.  
  62.             if (OverrideCursor == System.Windows.Forms.Cursors.Hand) {
  63.                 OverrideCursor = SystemHandCursor;
  64.             }
  65.         }
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement