elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  [Ayuda] Chrome69Tabcontrol - Control Extendido
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Ayuda] Chrome69Tabcontrol - Control Extendido  (Leído 1,762 veces)
**Aincrad**


Desconectado Desconectado

Mensajes: 668



Ver Perfil WWW
[Ayuda] Chrome69Tabcontrol - Control Extendido
« en: 4 Junio 2021, 22:28 pm »

Hola, hoy vengo a pedirles ayuda .

Tome el Tabcontrol, "Chrome69Tabcontrol " , lo pase a vb, y le agregue la posibilidad de arrastrar las pestañas de tabcontrol.

El problema es que quiero que desaparezca los botones de navigacion y no se como hacerlo :





Lo que quiero lograr es yo mismo calcular el tamaño disponible, y auto ajustar el tamaño de las pestañas, asi como lo hace Google Chrome.



Aqui el codigo :

Código
  1. Imports System.Drawing.Drawing2D
  2.  
  3. Namespace DragonTubeControls
  4.  
  5.    Public Class Helpers
  6.  
  7.        Public Shared Function Base64ToImage(ByVal Base64str As String) As System.Drawing.Image
  8.            Dim Fixb64 As String = Base64str.Replace(" ", "+")
  9.            Dim MemStream As System.IO.MemoryStream = New System.IO.MemoryStream(Convert.FromBase64String(Fixb64))
  10.            Dim ImageStream As Image = System.Drawing.Image.FromStream(MemStream)
  11.            MemStream.Close()
  12.            Return ImageStream
  13.        End Function
  14.  
  15.    End Class
  16.  
  17.    Public Class Chrome69Tabcontrol
  18.        Inherits TabControl
  19.  
  20. #Region " Decalre's "
  21.  
  22.        Private AddImageBlack As String = "iVBORw0KGgoAAAANSUhEUgAAABsAAAAcCAYAAACQ0cTtAAAAN0lEQVR42mNgGAWjYMiCyMiEh3SzLCoq8f+oZaOWgVMdyGBiMU1S6WicjVo2eMrGUTAKRsHgBgBNazNxj/heLwAAAABJRU5ErkJggg=="
  23.        Private CloseImageBlack As String = "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAQCAYAAADJViUEAAAAU0lEQVR42mNgGOHA3Nx8FRDboIubmZnZAsVX49UMVfQc2QCo2AsQTdB2mGKQASRpxGIAaRqhfrchSzNU43OQJpKcjayR5AADRRU2RVAD1jCMAgYAuEUszUWy7F8AAAAASUVORK5CYII="
  24.        Private predraggedTab As TabPage
  25.        Private ReferenceTabSize As New Size(505, 505)
  26.  
  27. #End Region
  28.  
  29.  
  30.        Const CLOSE_SIZE As Integer = 16
  31.  
  32.        Public Sub New()
  33.            MyBase.New()
  34.            SetStyles()
  35.            Me.SizeMode = TabSizeMode.Fixed
  36.            Me.Dock = DockStyle.Fill
  37.            Me.Font = New Font("Microsoft Yahei", 9.0F)
  38.            Me.ItemSize = New Size(245, 35)
  39.            Me.DoubleBuffered = True
  40.            Me.AllowDrop = True
  41.            ' Me.Multiline = True
  42.            '  Me.AutoSize = False
  43.        End Sub
  44.  
  45.  
  46.  
  47.        Private Sub SetStyles()
  48.            MyBase.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor, True)
  49.            MyBase.UpdateStyles()
  50.        End Sub
  51.  
  52.        Public Overrides ReadOnly Property DisplayRectangle As Rectangle
  53.            Get
  54.                Dim rect As Rectangle = MyBase.DisplayRectangle
  55.                Return New Rectangle(rect.Left - 8, rect.Top - 1, rect.Width + 12, rect.Height + 8)
  56.            End Get
  57.        End Property
  58.  
  59.        Protected Overrides Sub OnResize(ByVal e As EventArgs)
  60.            MyBase.OnResize(e)
  61.            Me.Refresh()
  62.            Me.Update()
  63.        End Sub
  64.  
  65.        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  66.            MyBase.OnPaint(e)
  67.            Dim rect As Rectangle = Me.ClientRectangle
  68.            e.Graphics.SmoothingMode = SmoothingMode.HighQuality
  69.            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear
  70.  
  71.            Using bufferedGraphics As BufferedGraphics = BufferedGraphicsManager.Current.Allocate(e.Graphics, rect)
  72.                bufferedGraphics.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(230, 232, 236)), rect)
  73.  
  74.                For index As Integer = 0 To Me.TabCount - 1
  75.                    DrawTabPage(bufferedGraphics.Graphics, Me.GetTabRect(index), index)
  76.                Next
  77.                bufferedGraphics.Render(e.Graphics)
  78.            End Using
  79.        End Sub
  80.  
  81.  
  82.  
  83.        Private Sub DrawTabPage(ByVal graphics As Graphics, ByVal rectangle As Rectangle, ByVal index As Integer)
  84.            graphics.SmoothingMode = SmoothingMode.HighQuality
  85.            graphics.InterpolationMode = InterpolationMode.HighQualityBilinear
  86.            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
  87.            '  Me.TabPages(index).AutoSize = False
  88.            '  rectangle.Size = Me.ItemSize
  89.  
  90.            Dim sf As StringFormat = New StringFormat()
  91.            sf.Trimming = StringTrimming.EllipsisCharacter
  92.            sf.FormatFlags = StringFormatFlags.NoWrap
  93.            Dim fontRect As Rectangle = New Rectangle(rectangle.X + 40, rectangle.Y + 7, rectangle.Width, Me.TabPages(index).Font.Height)
  94.            Dim rectClose As Rectangle = GetCloseRect(rectangle)
  95.            Dim p5 As Point = New Point(rectangle.Left, 7)
  96.            Dim p6 As Point = New Point(rectClose.X - 12, 12)
  97.  
  98.  
  99.  
  100.            Try
  101.  
  102.            If index = Me.TabCount - 1 Then
  103.  
  104.                    Using Add As Bitmap = Helpers.Base64ToImage(AddImageBlack)
  105.                        graphics.DrawImage(Add, p5)
  106.                    End Using
  107.  
  108.                Else
  109.  
  110.                    If index = Me.SelectedIndex Then
  111.  
  112.                        graphics.FillPath(New SolidBrush(Color.FromArgb(255, 255, 255)), CreateTabPath(rectangle))
  113.                        graphics.DrawString(Me.TabPages(index).Text, Me.TabPages(index).Font, New SolidBrush(Color.SlateGray), fontRect, sf)
  114.  
  115.                        If Me.ImageList IsNot Nothing Then
  116.                            Dim imgindex As Integer = Me.TabPages(index).ImageIndex
  117.                            Dim key As String = Me.TabPages(index).ImageKey
  118.                            Dim icon As Image = New Bitmap(32, 32)
  119.  
  120.                            If imgindex > -1 Then
  121.                                icon = Me.ImageList.Images(imgindex)
  122.                            End If
  123.  
  124.                            If Not String.IsNullOrEmpty(key) Then
  125.                                icon = Me.ImageList.Images(key)
  126.                            End If
  127.  
  128.                            graphics.DrawImage(icon, rectangle.Left + 22, rectangle.Top + 9)
  129.                        End If
  130.  
  131.                        Using Close As Bitmap = Helpers.Base64ToImage(CloseImageBlack)
  132.                            graphics.DrawImage(Close, p6)
  133.                        End Using
  134.  
  135.                    Else
  136.  
  137.                        graphics.FillPath(New SolidBrush(Color.FromArgb(230, 232, 236)), CreateTabPath(rectangle))
  138.                        graphics.DrawString(Me.TabPages(index).Text, Me.TabPages(index).Font, New SolidBrush(Color.Gray), fontRect, sf)
  139.  
  140.                        If Me.ImageList IsNot Nothing Then
  141.                            Dim imgindex As Integer = Me.TabPages(index).ImageIndex
  142.                            Dim key As String = Me.TabPages(index).ImageKey
  143.                            Dim icon As Image = New Bitmap(32, 32)
  144.  
  145.                            If imgindex > -1 Then
  146.                                icon = Me.ImageList.Images(imgindex)
  147.                            End If
  148.  
  149.                            If Not String.IsNullOrEmpty(key) Then
  150.                                icon = Me.ImageList.Images(key)
  151.                            End If
  152.  
  153.                            graphics.DrawImage(icon, rectangle.Left + 22, rectangle.Top + 9)
  154.                        End If
  155.  
  156.                        Using Close As Bitmap = Helpers.Base64ToImage(CloseImageBlack)
  157.                            graphics.DrawImage(Close, p6)
  158.                        End Using
  159.  
  160.                    End If
  161.                End If
  162.  
  163.            Catch __unusedNullReferenceException1__ As System.NullReferenceException
  164.            End Try
  165.        End Sub
  166.  
  167.        Protected Overrides Sub OnSelecting(ByVal e As TabControlCancelEventArgs)
  168.            If e.TabPageIndex = Me.TabPages.Count - 1 Then e.Cancel = True
  169.        End Sub
  170.  
  171. #Region " Mause Event "
  172.  
  173.        Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  174.            If e.Button = MouseButtons.Left AndAlso predraggedTab IsNot Nothing Then
  175.                Me.DoDragDrop(predraggedTab, DragDropEffects.Move)
  176.            End If
  177.  
  178.            MyBase.OnMouseMove(e)
  179.        End Sub
  180.  
  181.        Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  182.            predraggedTab = Nothing
  183.            MyBase.OnMouseUp(e)
  184.        End Sub
  185.  
  186.        Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  187.            MyBase.OnMouseDown(e)
  188.            Dim lastIndex As Integer = Me.TabCount - 1
  189.            Dim AddImage As Bitmap = Helpers.Base64ToImage(AddImageBlack)
  190.            Dim p5 As Point = New Point(Me.GetTabRect(lastIndex).Left, 5)
  191.            Dim AddImgRec = New Rectangle(p5, AddImage.Size)
  192.  
  193.            If Me.GetTabRect(lastIndex).Contains(e.Location) Then
  194.  
  195.                If AddImgRec.Contains(e.Location) Then
  196.                    Me.TabPages.Insert(lastIndex, "Chrome Tab")
  197.                    Me.SelectedIndex = lastIndex
  198.                End If
  199.            End If
  200.  
  201.            If e.Button = MouseButtons.Left Then
  202.  
  203.                ' Incomplete Bug
  204.                '  If Not Me.TabCount <= 3 Then
  205.                '      Dim Xw As Integer = Me.Width / Me.TabCount
  206.                '     If Xw > 245 Then Xw = 245                                  
  207.                '     Me.ItemSize = New Size(Me.Width / Me.TabCount, Me.ItemSize.Height)
  208.                ' End If
  209.  
  210.                Dim x As Integer = e.X, y As Integer = e.Y
  211.                Dim myTabRect As Rectangle = Me.GetTabRect(Me.SelectedIndex)
  212.                myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + 23), 5)
  213.                myTabRect.Width = CLOSE_SIZE
  214.                myTabRect.Height = CLOSE_SIZE
  215.                Dim isClose As Boolean = x > myTabRect.X AndAlso x < myTabRect.Right AndAlso y > myTabRect.Y AndAlso y < myTabRect.Bottom
  216.  
  217.                If isClose = True Then
  218.  
  219.                    If Me.TabPages.Count > 2 Then
  220.                        Dim tab As TabPage = Me.SelectedTab
  221.                        Me.TabPages.Remove(tab)
  222.                        Me.SelectedTab.Refresh()
  223.                        Me.SelectedIndex = Me.TabPages.Count - 2
  224.                        tab.Dispose()
  225.                        GC.Collect()
  226.                        GC.WaitForPendingFinalizers()
  227.                    Else
  228.                        System.Environment.[Exit](0)
  229.                        Dispose()
  230.                    End If
  231.                End If
  232.            End If
  233.  
  234.            predraggedTab = getPointedTab()
  235.        End Sub
  236.  
  237. #End Region
  238.  
  239. #Region " Private Methods "
  240.  
  241.        Private Function CreateTabPath(ByVal tabBounds As Rectangle) As GraphicsPath
  242.            Dim path As GraphicsPath = New GraphicsPath()
  243.            Dim spread, eigth, sixth, quarter As Integer
  244.            spread = CInt(Math.Floor(CDec(tabBounds.Height)))
  245.            eigth = CInt(Math.Floor(CDec(tabBounds.Height) * 1 / 11))
  246.            sixth = CInt(Math.Floor(CDec(tabBounds.Height) * 3 / 10))
  247.            quarter = CInt(Math.Floor(CDec(tabBounds.Height) * 2 / 3))
  248.            path.AddCurve(New Point() {New Point(tabBounds.X + 2, tabBounds.Bottom + 2), New Point(tabBounds.X + sixth, tabBounds.Bottom - eigth), New Point(tabBounds.X + spread - quarter, tabBounds.Y + eigth), New Point(tabBounds.X + spread, tabBounds.Y)})
  249.            path.AddLine(tabBounds.X + spread, tabBounds.Y, tabBounds.Right - spread, tabBounds.Y)
  250.            path.AddCurve(New Point() {New Point(tabBounds.Right - spread, tabBounds.Y), New Point(tabBounds.Right - spread + quarter, tabBounds.Y + eigth), New Point(tabBounds.Right - sixth, tabBounds.Bottom - eigth), New Point(tabBounds.Right + 2, tabBounds.Bottom + 2)})
  251.            path.CloseFigure()
  252.            Return path
  253.        End Function
  254.  
  255.        Private Function GetCloseRect(ByVal myTabRect As Rectangle) As Rectangle
  256.            myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + 10), 5)
  257.            myTabRect.Width = CLOSE_SIZE
  258.            myTabRect.Height = CLOSE_SIZE
  259.            Return myTabRect
  260.        End Function
  261.  
  262. #End Region
  263.  
  264. #Region " Other Events "
  265.  
  266.        Protected Overrides Sub OnDragOver(ByVal drgevent As DragEventArgs)
  267.            Dim draggedTab = CType(drgevent.Data.GetData(GetType(TabPage)), TabPage)
  268.            Dim pointedTab = getPointedTab()
  269.  
  270.            If ReferenceEquals(draggedTab, predraggedTab) AndAlso pointedTab IsNot Nothing Then
  271.                drgevent.Effect = DragDropEffects.Move
  272.  
  273.                If Not ReferenceEquals(pointedTab, draggedTab) Then
  274.                    Me.ReplaceTabPages(draggedTab, pointedTab)
  275.                End If
  276.            End If
  277.  
  278.            MyBase.OnDragOver(drgevent)
  279.        End Sub
  280.  
  281.        Private Function getPointedTab() As TabPage
  282.            For i = 0 To Me.TabPages.Count - 1
  283.                If Me.GetTabRect(i).Contains(Me.PointToClient(Cursor.Position)) Then
  284.                    Return Me.TabPages(i)
  285.                End If
  286.            Next
  287.  
  288.            Return Nothing
  289.        End Function
  290.  
  291.        Private Sub ReplaceTabPages(ByVal Source As TabPage, ByVal Destination As TabPage)
  292.            Try
  293.                Dim SourceIndex = Me.TabPages.IndexOf(Source)
  294.                Dim DestinationIndex = Me.TabPages.IndexOf(Destination)
  295.                Me.TabPages(DestinationIndex) = Source
  296.                Me.TabPages(SourceIndex) = Destination
  297.  
  298.                If Me.SelectedIndex = SourceIndex Then
  299.                    Me.SelectedIndex = DestinationIndex
  300.                ElseIf Me.SelectedIndex = DestinationIndex Then
  301.                    Me.SelectedIndex = SourceIndex
  302.                End If
  303.                Me.Refresh()
  304.            Catch ex As Exception
  305.  
  306.            End Try
  307.        End Sub
  308.  
  309. #End Region
  310.  
  311.    End Class
  312. End Namespace
  313.  


Gracias de antemano.



En línea



Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Final de Inception extendido! (El Origen - DiCaprio)
Foro Libre
Embusterillo de bolsillo 5 5,048 Último mensaje 21 Agosto 2010, 19:29 pm
por 16BITBoy
Monitor extendido
Windows
ElMag0 6 4,087 Último mensaje 20 Agosto 2012, 22:47 pm
por ElMag0
JOptionPane extendido
Java
alfrosende 4 2,575 Último mensaje 23 Marzo 2015, 22:56 pm
por alfrosende
Microsoft podría reducir los precios del soporte extendido
Noticias
wolfbcn 0 1,122 Último mensaje 18 Julio 2015, 17:19 pm
por wolfbcn
Firefox 60 ESR será la próxima versión con soporte extendido
Noticias
wolfbcn 0 2,310 Último mensaje 25 Diciembre 2017, 01:49 am
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines