Button click adds new documentwindow

7 posts, 1 answers
  1. eric
    eric avatar
    6 posts
    Member since:
    Aug 2010

    Posted 16 Jan 2011 Link to this post

    I want to create a document window tab on the dock when I click a button. how do I go about this?
    Thanks!!
    -Eric Pacheco
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Jan 2011 Link to this post

    Hello Eric,

    To create a document in RadDock from a button click, consider the following code
    Private Sub RadMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadMenuItem1.Click
        Dim documentTop As DocumentWindow = New DocumentWindow()
        documentTop.Text = "New Document"
        Me.RadDock1.AddDocument(documentTop)
    End Sub

    For more information on creating windows at runtime, please take a look at the following documentation

    hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. eric
    eric avatar
    6 posts
    Member since:
    Aug 2010

    Posted 16 Jan 2011 Link to this post

    okay great! how can I do a check to make sure only 1 tab gets created. so lets say they cant keep clicking the button and more will generate
  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Jan 2011 Link to this post

    Hi Eric,

    Just move the document to private and check to see if it is nothing. E.g.
    Private m_DocumentTop As DocumentWindow
    Private Sub RadMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadMenuItem1.Click
        If m_DocumentTop Is Nothing Then
            m_DocumentTop = New DocumentWindow()
            m_DocumentTop.Text = "New Document"
            Me.RadDock1.AddDocument(m_DocumentTop)
        End If
    End Sub

    Hope that helps
    Richard
  6. eric
    eric avatar
    6 posts
    Member since:
    Aug 2010

    Posted 28 Jan 2011 Link to this post

    Okay thanks, but how come when i  X out of the new window and click the button to create it again. it will not create. its not going back to null;
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Jan 2011 Link to this post

    Hi Eric,

    If you are allowing close, but still only want to show one, then you can use the folliwing solution:

    Private WithEvents m_DocumentTop As DocumentWindow
    Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
        Dim canCreate As Boolean
        If m_DocumentTop Is Nothing Then
            canCreate = True
        Else
            If Not m_DocumentTop.DockState = DockState.TabbedDocument Then
                canCreate = True
            End If
        End If
        If canCreate Then
            m_DocumentTop = New DocumentWindow()
            m_DocumentTop.Text = "New Document"
            Me.RadDock1.AddDocument(m_DocumentTop)
        End If
    End Sub

    Hope that helps
    Richard
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 29 Jan 2011 Link to this post

    Hello Eric,

    My apologies, it was rather late when I posted the code last night. This is much cleaner. (presuming you want to show the same document each time, and not a new one)

    Private m_Document As New DocumentWindow()
    Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
        m_Document.Text = "New Document"
        m_Document.CloseAction = DockWindowCloseAction.Hide
        Me.RadDock1.AddDocument(m_Document)
    End Sub

    It just makes sure that the current document window is hidden, can only be shown once, and can be closed and re-shown
    Let me know if you have any questions
    Richard
Back to Top
UI for WinForms is Visual Studio 2017 Ready