Last active
May 14, 2025 07:09
-
-
Save hmetgundogdu/ca51c8bcf337cdf14a4eac9b3b3b1e87 to your computer and use it in GitHub Desktop.
Revisions
-
hmetgundogdu revised this gist
May 13, 2025 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,14 +3,23 @@ public partial class NoBorderTabControl : TabControl /// <summary> /// Fine-tune adjustments to hide the border more precisely. /// </summary> public Padding BorderAdjustments { get; set; } = new() { Left = 6, Right = 6, Top = 2, Bottom = 6, }; [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; } private const string TAB_CONTROL_NAME = "TabControlAsNoBorder"; private const int TCM_FIRST = 0x1300; @@ -23,26 +32,17 @@ protected override void WndProc(ref Message m) RECT rc = Marshal.PtrToStructure<RECT>(m.LParam); // Adjust these values depending on your needs rc.Left -= BorderAdjustments.Left; rc.Right += BorderAdjustments.Right; rc.Top -= BorderAdjustments.Top; rc.Bottom += BorderAdjustments.Bottom; Marshal.StructureToPtr(rc, m.LParam, true); } base.WndProc(ref m); } public static TabControl ReplaceTabControl(Control originalParent, TabControl originalTabControl) { if (!originalParent.Controls.ContainsKey(TAB_CONTROL_NAME)) -
hmetgundogdu revised this gist
May 13, 2025 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ public partial class NoBorderTabControl : TabControl { /// <summary> /// Fine-tune adjustments to hide the border more precisely. /// </summary> public RECT BorderAdjustments { get; set; } = new() { Left = 6, Right = 6, -
hmetgundogdu created this gist
May 13, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,97 @@ public partial class NoBorderTabControl : TabControl { public RECT OffsetPixels { get; set; } = new() { Left = 6, Right = 6, Top = 2, Bottom = 6, }; private const string TAB_CONTROL_NAME = "TabControlAsNoBorder"; private const int TCM_FIRST = 0x1300; private const int TCM_ADJUSTRECT = TCM_FIRST + 40; protected override void WndProc(ref Message m) { if (m.Msg == TCM_ADJUSTRECT) { RECT rc = Marshal.PtrToStructure<RECT>(m.LParam); // Adjust these values depending on your needs rc.Left -= OffsetPixels.Left; rc.Right += OffsetPixels.Right; rc.Top -= OffsetPixels.Top; rc.Bottom += OffsetPixels.Bottom; Marshal.StructureToPtr(rc, m.LParam, true); } base.WndProc(ref m); } [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; } public static TabControl ReplaceTabControl(Control originalParent, TabControl originalTabControl) { if (!originalParent.Controls.ContainsKey(TAB_CONTROL_NAME)) { var newTabControl = new CustomTabControl { Name = TAB_CONTROL_NAME, Size = originalTabControl.Size, Width = originalTabControl.Width, Location = originalTabControl.Location, Dock = originalTabControl.Dock }; foreach (TabPage tabpage in originalTabControl.TabPages) { newTabControl.TabPages.Add(tabpage); } originalTabControl.Hide(); if (originalParent is TableLayoutPanel parentPanel) { int row = parentPanel.GetRow(originalTabControl); int column = parentPanel.GetColumn(originalTabControl); parentPanel.SetColumnSpan(newTabControl, parentPanel.GetColumnSpan(originalTabControl)); parentPanel.Controls.Add(newTabControl, column, row); } else { if (originalTabControl.Parent is null) { throw new InvalidOperationException("There is no parent of tab control here"); } originalTabControl.Parent.Controls.Add(newTabControl); } return newTabControl; } else { var controlNoBorder = originalParent.Controls[TAB_CONTROL_NAME]; if (controlNoBorder is TabControl) { return (TabControl)controlNoBorder; } else { throw new InvalidOperationException("There is no tab control in side of tab control parent children"); } } } }