This is a migrated thread and some comments may be shown as answers.

Cloning Document and Elements inside Container

2 Answers 147 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 30 Sep 2012, 02:46 PM
Hello,

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 Answers, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 03 Oct 2012, 01:28 PM
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()
            InitializeComponent()
 
            radMenu.Parent = Me
            Dim menuItem As New RadMenuItem("New")
            menuItem.Click += menuItem_Click
            radMenu.Items.Add(menuItem)
 
            radDock.Dock = DockStyle.Fill
            radDock.Parent = Me
            radDock.BringToFront()
            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
            radDock.AddDocument(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 >>
0
Dan
Top achievements
Rank 1
answered on 03 Oct 2012, 02:58 PM
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
        objWindow.Controls.Add(e)
        e.Dock = DockStyle.Fill
    
        Try
            Me.DocumentTabStrip1.Controls.Add(objWindow)
        Catch ex As Exception
            DocumentTabStrip1 = New Telerik.WinControls.UI.Docking.DocumentTabStrip()
            DocumentContainer1.Controls.Add(DocumentTabStrip1)
            Me.DocumentTabStrip1.Controls.Add(objWindow)
        End Try
End Sub


Thanks again.
Tags
Dock
Asked by
Dan
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Dan
Top achievements
Rank 1
Share this question
or