Calculating Tab Width in TabControl (Windows Forms)

I searched everywhere and it overheard me because it seems like I'm the only one who asked about this before. How do you calculate tab width in Windows Forms TabControl ?

Each tab that opens or is created in my application will have a variable length, and the font size and font used on these tabs may also change at runtime.

enter image description here

+4
source share
2 answers

I managed to solve this problem myself by looking at intellisense a bit more. The TabControl.GetTabRect() method returns the rectangle for the tab:

 Rectangle rect = this.tabControl1.GetTabRect(tabControl1.SelectedIndex); MessageBox.Show(rect.Width.ToString()); 
+3
source

You can get it using the ItemSize TabControl Property.

If you want to have the same width for all tabs, use the following:

 this.tabControl1.SizeMode = TabSizeMode.Fixed; 
+1
source

Source: https://habr.com/ru/post/1482895/


All Articles