Вопрос

Everything I want is shown a the picture below. How could I achieve that?

enter image description here

how to add any buttons at tabcontrol tabpages ? Or is that a custom controls that I need to create ?

First picture is from visual studio and second picture is from photoshop.

I also can find a way around that to let the user close it but I really need to achieve this as it's more user friendly.

Это было полезно?

Решение

The first example you showed is made using WPF which is quite easy to do if you already know WPF. The second example looks like Photoshop which is most likely a custom C++ Win32 control.

But if you're working with WinForms you usually can't do these kinds of customizations with the standard controls. You can write your own TabControl by deriving from Control and handling the painting and input yourself, which I've done in the past, but it's a lot of work too. Especially if you take into account that you have to manage a list of child controls for each tab. And that you may want design-time support for dragging and dropping other controls and panels into each tab and modifying the tab properties in the Visual Studio Designer. None of that is done for you if you go this route.

If you don't want to learn WPF, and you don't want to spend the week(s) it could take to write a robust custom control, you could look at companies such as Telerik, DevExpress, Infragistics, etc., you might be able to simply pay for a control library which a TabControl that already does this.

Другие советы

Here's a dumb way to do it...

Add some spaces and an X at the end of the tab name. In the click even capture the Mouse X and see if it is over the X.

Private Sub TabControl1_Click(sender As System.Object, e As System.EventArgs) Handles TabControl1.Click
    Dim m As System.Windows.Forms.MouseEventArgs = DirectCast(e, System.Windows.Forms.MouseEventArgs)
    Dim tabWidth As Integer =
        Convert.ToInt32(Me.CreateGraphics().MeasureString(TabControl1.SelectedTab.Text, TabControl1.Font).Width)
    Debug.Print(m.X & " " & m.Y & " " & tabWidth)
End Sub

A Sub/Func is needed to calculate the hot spots accounting for which tabs are displayed. Iterate over the visible tabs and use the tabWidth as shown above to do the math.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top