Create Button In VB.NET Programmatically And Save It as Permanence
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Create Button In VB.NET Programmatically And Save It as Permanence

  1. #1
    Join Date
    May 2012
    Posts
    6

    Unhappy Create Button In VB.NET Programmatically And Save It as Permanence

    Hi, All Experts ... Argent, Please HELP ...

    How to create a Button in Runtime and save it as Permanence. I Means to create Button or any control using coding but need it to save for next time using without using database to keep. Eg: Create a button during runtime, and the control will save permanencely for next use.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Not sure what you mean? A dynamic button is a dynamic button. Whether you save the settings for this button in an INI file, or even the registry, it will still have to be created dynamically from there.

  3. #3
    Join Date
    May 2002
    Location
    Boston
    Posts
    66

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Is this what you're looking for?

    Code:
    Public Class Form1
    
       
    Private myButton As Button
    
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Try
    
                myButton = New Button
    
                myButton.Size = New System.Drawing.Size(80, 24)
                myButton.Location = New System.Drawing.Point(40, 40)
                myButton.Text = "myButton"
                Controls.Add(myButton)
    
                AddHandler myButton.Click, AddressOf myButtonClick
    
    
            Catch ex As Exception
    
            End Try
        End Sub
    
        Private Sub myButtonClick()
    
            Try
                MessageBox.Show("OK")
            Catch ex As Exception
    
            End Try
        End Sub
    
     
    End Class

    Curt

  4. #4
    Join Date
    May 2012
    Posts
    6

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Quote Originally Posted by HanneSThEGreaT View Post
    Not sure what you mean? A dynamic button is a dynamic button. Whether you save the settings for this button in an INI file, or even the registry, it will still have to be created dynamically from there.
    Thanks, For Reply. YES, Currently I Save the setting in Local MS SQL Database, but every time in load slowly because too many setting inside, so what i want to find is the way to faster it ... Is that is i save those setting in .INI file will load faster ? Thanks.

  5. #5
    Join Date
    Apr 2012
    Posts
    29

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Well there would be less overhead reading from an INI file than an SQL Server database. So yes. However, that may not even be the source of your performance problems. Maybe there is something else causing it. Can't really be sure since we don't have the code you're using.

    Try the INI file route and see if that improves it.

  6. #6
    Join Date
    May 2012
    Posts
    6

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Oh, Thanks, I Will Try it using .INI file, and Another Question, how to make a dynamic created Button can be moveable follow the mouse drag position ? thanks.

  7. #7
    Join Date
    May 2012
    Posts
    6

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    By the way, how to write/read/create using .INI file ... Sry, I very fresh in VB.NET ... Thanks in advanced .

  8. #8
    Join Date
    May 2012
    Posts
    6

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Hi, Have anyone expert can tell me how to make faster Loading Control (Many Control) Like Button Dynamiclly Create at Runtime. The Loading for my from is slow and high latency until can see it load one-by-one. Becasue the Button Setting like position is all keep in Local Database. Thanks.

  9. #9
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Quote Originally Posted by CKS2009 View Post
    Oh, Thanks, I Will Try it using .INI file, and Another Question, how to make a dynamic created Button can be moveable follow the mouse drag position ? thanks.
    As Curt_c mentioned in his code, use AddHandler. Here is a link explaining how it works :

    http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx

    Courtesy of Google.

    Quote Originally Posted by CKS2009 View Post
    By the way, how to write/read/create using .INI file ... Sry, I very fresh in VB.NET ... Thanks in advanced .
    Have a look here :

    http://www.eggheadcafe.com/community...-ini-file.aspx

    Also via Google.

    Quote Originally Posted by CKS2009 View Post
    Hi, Have anyone expert can tell me how to make faster Loading Control (Many Control) Like Button Dynamiclly Create at Runtime. The Loading for my from is slow and high latency until can see it load one-by-one. Becasue the Button Setting like position is all keep in Local Database. Thanks.
    That is what we are trying to do. But I think you show really show us some of your code; there might be something else causing all the problems.

  10. #10
    Join Date
    May 2012
    Posts
    6

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Quote Originally Posted by HanneSThEGreaT View Post
    As Curt_c mentioned in his code, use AddHandler. Here is a link explaining how it works :

    http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx

    Courtesy of Google.



    Have a look here :

    http://www.eggheadcafe.com/community...-ini-file.aspx

    Also via Google.



    That is what we are trying to do. But I think you show really show us some of your code; there might be something else causing all the problems.

    Thks, but can gif any sample code on it ... i still cant successful apply for my case ... Thanks

  11. #11
    Join Date
    May 2002
    Location
    Boston
    Posts
    66

    Re: Create Button In VB.NET Programmatically And Save It as Permanence

    Hi,

    How many buttons are you creating on your form? if there's any delay it's probably from reading the database and not form creating the controls

    Why don't you just use 2 variables to locate your controls? Store those in a ini file.

    Code:
        Public Class Form1
    
        Private myButtons(30) As Button
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim i As Integer = 0
            Dim xStep As Integer = 40
            Dim yStep As Integer = 20
            Try
    
                For i = 0 To myButtons.Length - 1
    
                    myButtons(i) = New Button
    
                    myButtons(i).Size = New System.Drawing.Size(80, 24)
                    myButtons(i).Location = New System.Drawing.Point(xStep, yStep)
                    myButtons(i).Text = "Button " & i
                    'myButtons(i).Visible = False
                    Controls.Add(myButtons(i))
    
                    AddHandler myButtons(i).Click, AddressOf myButtonClick
    
                    yStep += 40
                    If i = 9 Or i = 19 Then
                        xStep = xStep + 100
                        yStep = 20
                    End If
    
                Next i
    
                'For i = 0 To myButtons.Length - 1
                '    myButtons(i).Visible = True
                'Next i
    
            Catch ex As Exception
    
                MessageBox.Show(ex.Message)
    
            End Try
    
        End Sub
    
        Private Sub myButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
            Try
                MessageBox.Show(sender.ToString())
            Catch ex As Exception
    
            End Try
        End Sub
    
    End Class

    Curt

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center