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

    1. Add the element TabControl In shape.

    2. Ask your properties. Alignment value Right

    3. Apply your properties. SizeMode value Fixed so that all deposits have the same width.

    4. For properties ItemSize Set the necessary fixed size of the deposit. Keep in mind that the properties ItemSize 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. Heightto make them higher, change properties Width

      To achieve optimal results in the example of the code below the characteristic Width relevant 25Height - meaning 100

    5. Ask your properties. DrawMode value OwnerDrawFixed

    6. Determine the processor for the event. DrawItem component TabControlto 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));
      

      }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2