C# - Padding TabPage справа
Мой TabPage
накладывается на элементы управления TabControl
потому что его ширина слишком велика. Мне нужно либо уменьшить его ширину, либо добавить его вправо.
(Как видно на этой картинке, фактическое TabPage
накладывает кнопки слева).
Вот мой обычай TabControl
учебный класс.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
namespace FlatUI
{
public class FlatTabControl : TabControl
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
private int W;
private int H;
protected override void CreateHandle()
{
base.CreateHandle();
Alignment = TabAlignment.Left;
}
protected override void OnHandleCreated(EventArgs e)
{
SendMessage(this.Handle, 0x1300 + 600, IntPtr.Zero, (IntPtr)10);
base.OnHandleCreated(e);
}
[Category("Colors")]
public Color BaseColor
{
get { return _BaseColor; }
set { _BaseColor = value; }
}
[Category("Colors")]
public Color ActiveColor
{
get { return _ActiveColor; }
set { _ActiveColor = value; }
}
private Color BGColor = Color.FromArgb(60, 70, 73);
private Color _BaseColor = Color.FromArgb(45, 47, 49);
private Color _ActiveColor = Helpers.FlatColor;
public FlatTabControl()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
DoubleBuffered = true;
BackColor = Color.FromArgb(60, 70, 73);
Font = new Font("Segoe UI", 10);
SizeMode = TabSizeMode.Normal;
ItemSize = new Size(130, 60);
}
protected override void OnPaint(PaintEventArgs e)
{
this.UpdateColors();
Bitmap B = new Bitmap(Width, Height);
Graphics G = Graphics.FromImage(B);
W = Width - 1;
H = Height - 1;
var _with13 = G;
_with13.SmoothingMode = SmoothingMode.HighQuality;
_with13.PixelOffsetMode = PixelOffsetMode.HighQuality;
_with13.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
_with13.Clear(_BaseColor);
try
{
SelectedTab.BackColor = Color.White;
}
catch
{
}
for (int i = 0; i <= TabCount - 1; i++)
{
Rectangle Base = new Rectangle(new Point(GetTabRect(i).Location.X + 2, GetTabRect(i).Location.Y), new Size(GetTabRect(i).Width, GetTabRect(i).Height));
Rectangle BaseSize = new Rectangle(Base.Location, new Size(Base.Width + 50, Base.Height));
Rectangle BaseSize2 = new Rectangle(Base.Location, new Size(Base.Width + 50, Base.Height + 30));
if (i == SelectedIndex)
{
//-- Base
_with13.FillRectangle(new SolidBrush(_BaseColor), Base);
//-- Gradiant
//.fill
_with13.FillRectangle(new SolidBrush(_ActiveColor), BaseSize);
//-- ImageList
if (ImageList != null && TabPages[i].ImageIndex != -1)
{
try
{
if (ImageList.Images[TabPages[i].ImageIndex] != null)
{
//-- Image
_with13.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(BaseSize.Location.X + 8, BaseSize.Location.Y + 6));
//-- Text
_with13.DrawString("\n\n\n" + TabPages[i].Text, Font, Brushes.White, BaseSize, Helpers.CenterSF);
_with13.DrawString("\n\n\nIn Queue", Font, Brushes.White, BaseSize2, Helpers.CenterSF);
}
else
{
//-- Text
_with13.DrawString(TabPages[i].Text, Font, Brushes.White, BaseSize, Helpers.CenterSF);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
else
{
//-- Text
_with13.DrawString(TabPages[i].Text, Font, Brushes.White, BaseSize, Helpers.CenterSF);
}
}
else
{
//-- Base
_with13.FillRectangle(new SolidBrush(_BaseColor), BaseSize);
//-- ImageList
if (ImageList != null && TabPages[i].ImageIndex != -1)
{
try
{
if (ImageList.Images[TabPages[i].ImageIndex] != null)
{
//-- Image
_with13.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(BaseSize.Location.X + 8, BaseSize.Location.Y + 6));
//-- Text
_with13.DrawString("\n\n\n" + TabPages[i].Text, Font, new SolidBrush(Color.Black), BaseSize, new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
}); _with13.DrawString("\n\n\nIn Queue", Font, new SolidBrush(Color.Black), BaseSize2, new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
});
}
else
{
//-- Text
_with13.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.Black), BaseSize, new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
});
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
else
{
//-- Text
_with13.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.Black), BaseSize, new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
});
}
}
}
base.OnPaint(e);
G.Dispose();
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.DrawImageUnscaled(B, 0, 0);
B.Dispose();
}
private void UpdateColors()
{
FlatColors colors = Helpers.GetColors(this);
_ActiveColor = colors.Flat;
}
}
}
Как мне этого добиться?
1 ответ
Благодаря предложению @HansPassant я воссоздал TabControl без вкладок, изменил ItemSize и только потом перепутал с внутренним кодом.