Change in the text in the deposits
-
Hello! I have a question. How can the text be changed in the deposits into the TabControl management element. This is standard location, properties Alignment = Top
Here. Alignment = Left
How to change the direction of the text to make it normal. If someone's been dealing with this question, tell me.
-
The simplest solution is MSDN: https://msdn.microsoft.com/ru-ru/library/ms404305%28v=vs.110%29.aspx
Demonstration of the right-wing deposit
Add the element
TabControl
In shape.Ask your properties.
Alignment
valueRight
♪Apply your properties.
SizeMode
valueFixed
so that all deposits have the same width.For properties
ItemSize
Set the necessary fixed size of the deposit. Keep in mind that the propertiesItemSize
Behaves like, As if the deposits were upside down, even though they were Bounded on the right edge. So to increase the width We need to change the properties.Height
to make them higher, change propertiesWidth
♪To achieve optimal results in the example of the code below the characteristic
Width
relevant25
♪Height
- meaning100
♪Ask your properties.
DrawMode
valueOwnerDrawFixed
♪Determine the processor for the event.
DrawItem
componentTabControl
to the right.public Form1() { // Remove this call if you do not program using Visual Studio. InitializeComponent();
tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem);
}
private void tabControl1_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush _textBrush;// Get the item from the collection. TabPage _tabPage = tabControl1.TabPages[e.Index]; // Get the real bounds for the tab rectangle. Rectangle _tabBounds = tabControl1.GetTabRect(e.Index); if (e.State == DrawItemState.Selected) { // Draw a different background color, and don't paint a focus rectangle. _textBrush = new SolidBrush(Color.Red); g.FillRectangle(Brushes.Gray, e.Bounds); } else { _textBrush = new System.Drawing.SolidBrush(e.ForeColor); e.DrawBackground(); } // Use our own font. Font _tabFont = new Font("Arial", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel); // Draw string. Center the text. StringFormat _stringFlags = new StringFormat(); _stringFlags.Alignment = StringAlignment.Center; _stringFlags.LineAlignment = StringAlignment.Center; g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags));
}