Advertisement
fortsoft

TabControl

Jan 8th, 2023 (edited)
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 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) 2011 Mike Zhang - MSDN Community Support
  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.Runtime.InteropServices;
  29.  
  30. namespace FortSoft.Controls {
  31.  
  32.     /// <summary>
  33.     /// Implements custom TabControl with only 1px border.
  34.     /// </summary>
  35.     public class TabControl : System.Windows.Forms.TabControl {
  36.  
  37.         /// <summary>
  38.         /// Constant value found in the Windows.h header file.
  39.         /// </summary>
  40.         private const int TCM_ADJUSTRECT = 0x1328;
  41.  
  42.         /// <summary>
  43.         /// Disabling background redraw will prevent tabs from flickering.
  44.         /// </summary>
  45.         protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) { }
  46.  
  47.         /// <summary>
  48.         /// A callback function that processes messages sent to a window.
  49.         /// </summary>
  50.         protected override void WndProc(ref System.Windows.Forms.Message message) {
  51.             if (message.Msg == TCM_ADJUSTRECT) {
  52.                 RECT rect = (RECT)message.GetLParam(typeof(RECT));
  53.                 rect.Left = Left - Margin.Left;
  54.                 rect.Right = Right + Margin.Right;
  55.                 rect.Top = Top - Margin.Top;
  56.                 rect.Bottom = Bottom + Margin.Bottom;
  57.                 Marshal.StructureToPtr(rect, message.LParam, true);
  58.             }
  59.             base.WndProc(ref message);
  60.         }
  61.  
  62.         /// <summary>
  63.         /// A rectangle structure to be marshalled.
  64.         /// </summary>
  65.         private struct RECT {
  66.             public int Left, Top, Right, Bottom;
  67.         }
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement