Cloning Document and Elements inside Container

3 posts, 1 answers
  1. Dan
    Dan avatar
    4 posts
    Member since:
    Sep 2012

    Posted 30 Sep 2012 Link to this post


    What is the best solution to creating a new tab at runtime which contains elements in VB.NET 2012.

    For example, <from users view>

    1. File > New
    2. <sees new tab> <new tab contains another control for editing text>

    This process can be repeated and tabs can be closed, however I still need to be notified if the text has changed inside selected tab X, and also to be able to make changes to it (aka, bold, load text from a file, etc).

    Thanks in advance.
  2. Answer
    Julian Benkov
    Julian Benkov avatar
    1135 posts

    Posted 03 Oct 2012 Link to this post

    Hi Daniel,

    You can use RadDock control to implement this functionality. Here is a example:
    Imports System
    Imports System.Windows.Forms
    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls.UI.Docking
    Namespace Lab.Dock
        Public Partial Class DockRichTextBoxDocumentForm
            Inherits Form
            Private radDock As New RadDock()
            Private radMenu As New RadMenu()
            Public Sub New()
                radMenu.Parent = Me
                Dim menuItem As New RadMenuItem("New")
                menuItem.Click += menuItem_Click
                radDock.Dock = DockStyle.Fill
                radDock.Parent = Me
                radDock.DockWindowClosing += radDock_DockWindowClosing
            End Sub
            Private Sub radDock_DockWindowClosing(sender As Object, e As DockWindowCancelEventArgs)
                If e.NewWindow.Controls.Count > 0 Then
                    Dim richTextBox As RichTextBox = TryCast(e.NewWindow.Controls(0), RichTextBox)
                    If richTextBox.Modified Then
                        If DialogResult.No = MessageBox.Show("Are you sure you want to close this window", "MyApp", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Then
                            e.Cancel = True
                        End If
                    End If
                End If
            End Sub
            Private Sub menuItem_Click(sender As Object, e As EventArgs)
                Dim document As New DocumentWindow()
                Dim radRichTextBox As New RichTextBox()
                radRichTextBox.Dock = DockStyle.Fill
                radRichTextBox.Parent = document
            End Sub
        End Class
    End Namespace

    I hope this helps.

    Kind regards,
    Julian Benkov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. Dan
    Dan avatar
    4 posts
    Member since:
    Sep 2012

    Posted 03 Oct 2012 Link to this post

    Thank you for the clean and well formatted response.

    I did find a solution very similar solution by browsing through how the objects are created and attached in the Form.Designer.vb code.

    For the record, the code I can up with was as follows, which allows for closing of all DocumentWindows via the Try/Catch routine which handles checking to see if the container still exists. I thought I would share this method on this thread for anyone else looking this up, and they can have a solution for both methods.

    Sub NewWindow(ByVal Caption as String, ByVal Tip as String, ByRef e as Object)
            Dim objWindow = New Telerik.WinControls.UI.Docking.DocumentWindow()
            objWindow.Text = FileName
            objWindow.ToolTipText = ToolTip
            e.Dock = DockStyle.Fill
            Catch ex As Exception
                DocumentTabStrip1 = New Telerik.WinControls.UI.Docking.DocumentTabStrip()
            End Try
    End Sub

    Thanks again.
Back to Top