Results 1 to 7 of 7

Thread: Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    3

    Unhappy Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

    I need to know how to have a button on a tab to create another button on a second tab that contains a panel, with appropriate spacing, the same size as other buttons already present, and the name of the tab that generated this new button as the text on the newly created button. I.e. button1 on tab1 will create and place a new button on a panel in tab2 that already has a grid of buttons (maybe 3x10 buttons) which will be placed underneath a particular column with the text tab2 on the new button which can also refer back to that tab automatically. Hopefully we can get all this code under a single button event.

    I also don't know how to have a button on tab1 that focuses on tab2, which sets the back button on tab2 with a reference to go back to tab1 in order to remain dynamic. I.e. clicking on tab1's button will go to tab2 and set the back button there with a link back to the tab it was referred from.

    I'd also like to know if there's an easy way to create and destroy tabs with a specific layout. I.e. We have home tab, and comment tab. (This is for the sake of argument) On the comment tab1 (which contains all posted comments), we have a new comment button which creates a comment tab2 (or a dialog box for that matter) with appropriate textboxes, labels, and buttons in the right places which could also make use of the issues I posted above. So the new comment button on the comment tab1 will create either a new comment tab2 with appropriate objects, or a dialog box with the same, and then the submit button on this comment tab2 or box will create a new textfield/buttons on the panel containing the grid of buttons with the information provided in the fields from comment tab2/dialog box which is then destroyed.

    I hope i haven't made the examples too confusing, but I can't figure out how to even make progress in these directions. Trying either fails completely, or semi-fails in getting these examples to function 100%.

    I've already tried posting in other forums, but with no replies. Hopefully you all can help me figure this out.

    EDIT: This is not homework, I have scoured forums and google trying to find the answer to these problems. I'm hoping that because these are mainly VB based forums I can find some answers here.
    Last edited by korsen; Feb 18th, 2010 at 01:24 PM.

  2. #2
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Re: Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

    Is this a windows app or a web app? I only ask because you mention links and having back buttons.
    If someone has helped you, please make sure to rate them.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    3

    Re: Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

    Right! It's a windows app. At some point in the future it will have access to the internet but won't be a web app. I don't know any other way to put it. I'm familiar with a bit of C++ so i'm used to that language and all i can think of are pointers, but I have no clue how to do such things correctly in VB.

    EDIT: While we're at it, it's going to be for a touch screen panel.
    Last edited by korsen; Feb 18th, 2010 at 10:46 PM.

  4. #4
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Re: Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

    Quote Originally Posted by korsen View Post
    I need to know how to have a button on a tab to create another button on a second tab that contains a panel, with appropriate spacing, the same size as other buttons already present, and the name of the tab that generated this new button as the text on the newly created button. I.e. button1 on tab1 will create and place a new button on a panel in tab2 that already has a grid of buttons (maybe 3x10 buttons) which will be placed underneath a particular column with the text tab2 on the new button which can also refer back to that tab automatically. Hopefully we can get all this code under a single button event.
    Why create the button, why not show it when you need it and assign text to it. If you need it to do a particular process based on it's text, then handle that in the click event of the button.

    Quote Originally Posted by korsen View Post
    I also don't know how to have a button on tab1 that focuses on tab2, which sets the back button on tab2 with a reference to go back to tab1 in order to remain dynamic. I.e. clicking on tab1's button will go to tab2 and set the back button there with a link back to the tab it was referred from.
    I am not sure why you need to create your own navigation system for the Tab Control. The TabControl does a very good job of switching tabs by itself.

    Quote Originally Posted by korsen View Post
    I'd also like to know if there's an easy way to create and destroy tabs with a specific layout. I.e. We have home tab, and comment tab. (This is for the sake of argument) On the comment tab1 (which contains all posted comments), we have a new comment button which creates a comment tab2 (or a dialog box for that matter) with appropriate textboxes, labels, and buttons in the right places which could also make use of the issues I posted above. So the new comment button on the comment tab1 will create either a new comment tab2 with appropriate objects, or a dialog box with the same, and then the submit button on this comment tab2 or box will create a new textfield/buttons on the panel containing the grid of buttons with the information provided in the fields from comment tab2/dialog box which is then destroyed.
    Why create and destroy tabs, seems like a lot of overhead. Either show or don't show relevant tabs. A dialog box would probably be your best bet to get information to enter. I would create your own dialog box with public properties then pull your values from the properties of the instance of the dialog box. For example, here my own dialog box has a textbox, checkbox, and a numericupdown.
    Code:
    Public Class MyOwnDialogWithPropertiesToReturn
    
        Public ReadOnly Property MyOwnAge() As Decimal
            Get
                Return Me.NumericUpDown1.Value
            End Get
        End Property
    
        Public ReadOnly Property MyOwnName() As String
            Get
                Return TextBox1.Text
            End Get
        End Property
    
        Public ReadOnly Property MyOwnFun() As Boolean
            Get
                Return CheckBox1.Checked
            End Get
        End Property
    
        Private ReadOnly Property IsFormValid() As Boolean
            Get
                Return (Not String.IsNullOrEmpty(TextBox1.Text.Trim()))
            End Get
        End Property
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
            If Me.IsFormValid Then
                Me.DialogResult = Windows.Forms.DialogResult.OK
    
                Me.Close()
            End If
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.DialogResult = Windows.Forms.DialogResult.Cancel
            Me.Close()
    
        End Sub
    End Class
    And on my form I make the instance of myown dialog and then refer to the properties to get information back from the dialog.

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim frm As New MyOwnDialogWithPropertiesToReturn
            Dim Aging As Decimal = frm.MyOwnAge
            Dim Naming As String = frm.MyOwnName
            Dim HavingFun As Boolean = frm.MyOwnFun
    
            'get values 
            If frm.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Aging = frm.MyOwnAge
                Naming = frm.MyOwnName
                HavingFun = frm.MyOwnFun
    
            End If
        End Sub

    Quote Originally Posted by korsen View Post
    I hope i haven't made the examples too confusing, but I can't figure out how to even make progress in these directions. Trying either fails completely, or semi-fails in getting these examples to function 100%.
    It is kind of confusing what you want to do. If you could post some code it would help a lot or a screen shot or two of what you want, code would be best though.
    If someone has helped you, please make sure to rate them.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    3

    Re: Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

    It's really proprietary information what i'm trying to do. I wish I could just put it out but for my own safety it needs to remain covered until i'm ready to display it.

    Creating the new button, i'm allowing people to track "articles" where there will be a column of the articles they want tracked. If they want to track another one, clicking the button to track the one they're viewing should create a new button on the tracked list of buttons, with the main title of the article on the button for easy locating.

    The reason why I need the button to go back and forth between tabs dynamically is because say for each article there will be a new tab with all the relevant information on it. Plus, the tab with the article on it needs to know where it just sent you so that you can go back. If you want to add a comment, the back button on the comment page needs to know you came from article 37 and not the home page. Once again, this is a regular application with internet access, and not a web app. These articles will be presented to the user via server databases that will upload the information to a newly created tab, and I need the buttons on those tabs to behave dynamically because who knows where the user wants to go to and from, etc. I could just as easily have the tabcontrol do what I need it to do, if only I didn't need new pages and buttons with the right links on the fly. It's just a result of the kind of program i'm developing.

    Now, showing and hiding relevant tabs and having a hidden dialog box automatically do work, is a great idea. Never though about it. Thank you.

    So for the first few issues i'm having, there will be a search bar on the home page where people can search for the article they're looking for. It'll give them some options... which is another thing I need help figuring out. I suppose I could just allow the search filter to transfer links/button.text from the results, and just use a fixed number of buttons, but how would I get the search function to dynamically create the same number of buttons as there would be results? i.e.

    (Btw, this code does NOT work, it's just to get my idea across)

    Private Sub Searchbox1_Keys.Enter (etc) Handles whatever
    Tabcontrol1.searchtab = Hidden.false
    SearchPanel.Objects.Add(Button, numSearchResults)
    [Organize Button Locations, size, button.text functions]
    Timer(5 minutes) = Tabcontrol1.searchtab = Hidden.true
    [Clear the panel for new search result functions]
    End Sub

    Next Idea code:

    Private Sub Trackarticle_Click (etc) Handles whatever
    HomePanel.Objects.Add(Button, button.text = articlename.text)
    [Organize New Button size, layout, text functions on home panel]
    ArticleCheckBox.State = checked (code looking for unchecked state will remove the button this creates when the user is done tracking it)
    End Sub

    Next Idea code:
    (A few examples to make sure it's clear)

    Private Sub Searchbar_Keys.Enter (etc)
    Tabcontrol1.searchtab = hidden.false
    Tabcontrol1.searchtab.focus
    SearchBack.click = tabcontrol1.homepage (going back from the search will go home)
    End Sub

    Private Sub SearchResult37_Click (etc)
    Tabcontrol1.Articlepage = hidden.false
    Tabcontrol1.articlepage.focus
    ArticleBack.click = tabcontrol1.searchtab (there may be more than one article open at a time, so the code needs to be dynamic enough to be able to tell which new article just opened and set properties of respective buttons.)
    End Sub

    These two functions would need to be combined somehow...

    This is also a good example of why i need to create/destroy tabs. People might want to have several open and I could always set a limit of hidden tabs (5-10) but that would limit users. Since this is going to be a standalone product (with it's own hardware) I suppose thinking about it would say that i'll actually be able to limit users with a set amount of tabs, considering I need to make sure the software doesn't bog the entire thing down. Since these article tabs will contain rather large amounts of text I suppose i'll have no choice but to limit the number of tabs open to optimize processor and ram use, and therefore can set a limit of hidden tabs, eliminating my need to dynamically create and destroy. I think i'll have to have your dialog boxes catch the uploaded data and transfer it to appropriate boxes and just leave these hidden tabs empty, and clear them when i'm done. However, that still means I need to create and destroy buttons dynamically as well as place them in the appropriate places they need to go.

    But, let me say thank you again for solving one of my problems already (could be 2!) Once I figure out dynamic button creation I suppose the next thing i'll need to learn is how to embed internet access and database functions. Any good links for tutorials or info on that? Also, i'm eventually going to need to learn how to encrypt the data - ideas?

  6. #6
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Re: Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

    This code is specific to adding a button to a panel. You need to pass the panel to the function, the text of the button you want to create, and optionally you can pass the integer parameters for the location relative to the panel. The functions are shared so they can be placed in a separate module or class and then used in multiple places.

    Code:
     Public Shared Sub MakeButton(ByVal PassPanel As Panel, ByVal PassButtonText As String, Optional ByVal PassXLocation As Integer = -1, Optional ByVal PassYLocation As Integer = -1)
    
            Dim btn As Button
    
            Dim ButtonExists As Boolean = False
            'Search the panel for a button with the same text already
            For Each ctl As Control In PassPanel.Controls
                If TypeOf ctl Is Button Then
                    ButtonExists = (CType(ctl, Button).Text = PassButtonText)
                End If
            Next
    
            If Not ButtonExists Then
                'make button
                btn = New Button
    
                btn.Text = PassButtonText
                btn.Name = Guid.NewGuid.ToString.Replace("-", "")
    
                'set the location relative to the panel
                If PassXLocation < 0 Then
                    ' static location for button
                    btn.Location = New Point(23, 45)
                Else
                    'dynamic location for button 
                    btn.Location = New Point(PassXLocation, PassYLocation)
                End If
    
                'set the size
                btn.Size = New Size(20, 15)
    
                'assign the click event
                AddHandler btn.Click, AddressOf TabbedButtonClickEvent
    
                'add the button to the panel 
                PassPanel.Controls.Add(btn)
    
            End If
    
    
        End Sub
    
        Public Shared Sub TabbedButtonClickEvent(ByVal sender As Object, ByVal e As System.EventArgs)
            MessageBox.Show(CType(sender, Button).Text & "_clicked")
    
        End Sub
    Last edited by demausdauth; Feb 22nd, 2010 at 11:41 AM.
    If someone has helped you, please make sure to rate them.

  7. #7
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Re: Add Buttons to panel, button/tab references, create/destroy entire tabs/layouts

    Removal of controls can be fairly simple if you know the control's Name.

    Code:
    MyPanel.Controls.RemoveByKey(ButtonName)
    I think that in the TabControl SelectedIndexChanged event you will be able to add and remove your buttons as you want to.
    If someone has helped you, please make sure to rate them.

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