Private Sub button1_MouseDown(sender As Object, e As MouseEventArgs) button1.DoDragDrop(button1.Name, DragDropEffects.Copy) End Sub Private Sub tabControl1_DragEnter(sender As Object, e As DragEventArgs) e.Effect = DragDropEffects.Copy End Sub Private Sub tabControl1_DragDrop(sender As Object, e As DragEventArgs) Dim button As New Button() button.Text = e.Data.GetData(GetType(String)).ToString() Dim newPos As Point = PointToClient(New Point(e.X, e.Y)) button.Left = newPos.X - tabControl1.Left button.Top = newPos.Y - tabControl1.Top tabControl1.TabPages(0).Controls.Add(button) If button.Top + button.Height > tabControl1.TabPages(0).Height Then 'If the button is going out of the TabControl tabControl1.Height = tabControl1.Height + (button.Top + button.Height - tabControl1.TabPages(0).Height) tabControl1.TabPages(0).Invalidate() End If End Sub
Auto-converted your code to VB.Net. This is a VB.Net forum. Post code in VB.Net language for future.Hi cannorth,
It is still possible to make your own AutoSize function to the TabControl.
For example, if I am dragging some button into my TabControl.