Results 1 to 4 of 4

Thread: Strange Problem with mdi tabcontrol

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    164

    Strange Problem with mdi tabcontrol

    Code:
    
    Public Class Form1
           Dim WebBrowserA, WebBrowserB As New WebBrowser
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' WebPage   Inside the Tabcontrol
             Dim MyFristPage As New Form
            MyFristPage.Size = New Point(500, 500)
            MyFristPage.Location = New Point(500, 500)
            MyFristPage.Text = "Loading"
            TabControl1.TabPages.Add(MyFristPage)
            WebBrowserA.Dock = DockStyle.Fill
            WebBrowserA.Parent = MyFristPage
            WebBrowserA.Navigate("http://www.cyberspacers.com/games/Piano.swf")
         
               
    ' Webpage on MainForm
            WebBrowserB.Parent = Me
            WebBrowserB.Top = Me.Top - 50
            WebBrowserB.Left = Me.Width / 2
            WebBrowserB.Width = Me.Width / 2
            WebBrowserB.Height = Me.Height - 50
           
            WebBrowserB.Navigate("http://www.cyberspacers.com/games/Piano.swf")
       
        End Sub
    
        Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
            TabControl1.Width = Me.Width / 2
            WebBrowserB.Left = Me.Width / 2
            WebBrowserB.Width = Me.Width / 2
        End Sub
    I have problem to play the piano swf inside the TabControl1 (WebBrowserA), but i can play piano swf within the main form (WebBrowserB).

    Anyone know why, and the method to solve it to play at tabcontrol1
    Last edited by edwinho; May 24th, 2012 at 01:47 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    164

    Re: Strange Problem with tabcontrol

    I am using The MDI Tabcontrol,,,, If i change to VB original Tabcontrol the problem Gone....Any One Know How to solve it to play with MDI-Tabcontrol..........

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    164

    Re: Strange Problem with mdi tabcontrol

    I found some information about the MDI Tabcontrol,

    The one I used not support Active X!!!
    Are there any MDI Tabcontrol Which is supported the Active X and have Close Button!!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    164

    Re: Strange Problem with mdi tabcontrol

    I found the solution:-
    No Class Needed ,It used the VB default tabcontrol and have Close Button, and change the selected or non-selected tabpage color as user-define.

    It can Play the Piano Swf without Problem.

    Code:
    Public Class Form1
        Dim _imgHitArea As Point = New Point(13, 2)
        Dim _imageLocation As Point = New Point(15, 5)
        Dim X As Integer = 0
        Public Sub New()
            ' This call is required by the Windows Form Designer.
            ' Add any initialization after the InitializeComponent() call.
            InitializeComponent()
            'Set the Mode of Drawing as Owner Drawn    
            TabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
            'Add the Handler to draw the Image on Tab Pages     
            AddHandler TabControl1.DrawItem, AddressOf TabControl1_DrawItem
        End Sub
    
    
    
        Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)
          
    
            'set the Page selected color adn non-selected page color
            Try
    
                Dim g As Graphics = e.Graphics
                Dim tp As TabPage = TabControl1.TabPages(e.Index)
                Dim br As Brush
                Dim sf As New StringFormat
                Dim rt As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2)
                sf.Alignment = StringAlignment.Center
                Dim strTitle As String = tp.Text
                'If the current index is the Selected Index, change the color
                If TabControl1.SelectedIndex = e.Index Then
                    'this is the background color of the tabpage
                    'you could make this a stndard color for the selected page
                    '  br = New SolidBrush(tp.BackColor)
                    br = New SolidBrush(Color.Yellow)
                    'this is the background color of the tab page
                    g.FillRectangle(br, e.Bounds)
                    'this is the background color of the tab page
                    'you could make this a stndard color for the selected page
                    br = New SolidBrush(tp.ForeColor)
                    ' br = New SolidBrush(tp.ForeColor)
                    g.DrawString(strTitle, TabControl1.Font, br, rt, sf)
                Else
                    'these are the standard colors for the unselected tab pages
                    br = New SolidBrush(Color.WhiteSmoke)
                    g.FillRectangle(br, e.Bounds)
                    br = New SolidBrush(Color.Black)
                    g.DrawString(strTitle, TabControl1.Font, br, rt, sf)
                End If
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            'draw close Button
            Try
                'Close Image to draw       
                Dim img As Image = New Bitmap(My.Application.Info.DirectoryPath & "/close.gif")
                Dim r As Rectangle = e.Bounds
                r = Me.TabControl1.GetTabRect(e.Index)
                r.Offset(2, 2)
                Dim TitleBrush As Brush = New SolidBrush(Color.Black)
                Dim f As Font = Me.Font
                Dim title As String = Me.TabControl1.TabPages(e.Index).Text
                '  e.Graphics.DrawString(title, f, TitleBrush, New PointF(r.X, r.Y))
                e.Graphics.DrawImage(img, New Point(r.X + (Me.TabControl1.GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y))
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
        End Sub
    
        Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
    
            Dim tc As TabControl = CType(sender, TabControl)
            Dim p As Point = e.Location
            Dim _tabWidth As Integer
            _tabWidth = Me.TabControl1.GetTabRect(tc.SelectedIndex).Width - (_imgHitArea.X)
            Dim r As Rectangle = Me.TabControl1.GetTabRect(tc.SelectedIndex)
            r.Offset(_tabWidth, _imgHitArea.Y)
            r.Width = 16
            r.Height = 16
            If r.Contains(p) Then
                Dim TabP As TabPage = DirectCast(tc.TabPages.Item(tc.SelectedIndex), TabPage)
                tc.TabPages.Remove(TabP)
            End If
            
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            TabControl1.SizeMode = TabSizeMode.Fixed ' set the tabpage mode
            TabControl1.ItemSize = New Size(200, 20) 'set the Size of Tabpage
    
            TabControl1.TabPages.Clear()
    
    
            For I = 0 To 2
    
                Dim myTabPage As New TabPage()
                
    
    
                myTabPage.Text = "webbrowser" & X
                TabControl1.TabPages.Add(myTabPage)
                Dim Web As New WebBrowser
                myTabPage.Controls.Add(Web)
                Web.Name = "webbrowser" & X
                Web.Dock = DockStyle.Fill
                Web.ScriptErrorsSuppressed = True
                Web.ScrollBarsEnabled = True
                Web.Navigate("http://www.google.com")
                X = X + 1
            Next
        End Sub
    
        Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdd.Click
    
    
            Dim myTabPage As New TabPage()
    
    
            myTabPage.Text = "webbrowser" & X
            TabControl1.TabPages.Add(myTabPage)
            Dim Web As New WebBrowser
            myTabPage.Controls.Add(Web)
            Web.Name = "webbrowser" & X
            Web.Dock = DockStyle.Fill
            Web.ScriptErrorsSuppressed = True
            Web.ScrollBarsEnabled = True
            Web.Navigate("http://www.google.com")
            X = X + 1
        End Sub
    
        Private Sub ButtonRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRemove.Click
            TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
           
    
        End Sub
    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width