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

How to save dynamically created buttons

1 Answer 374 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
obi
Top achievements
Rank 1
obi asked on 10 Aug 2019, 07:42 PM

I use the following code to create button dynamically. Please how can I save the button so that it will appear on next run? I have been looking for a solution and could not find one.

Dim count As Integer = RadLayoutControl.Controls.OfType(Of Button).ToList.Count

Dim button As Button = New Button

 button.Size = New System.Drawing.Size(RadSpinEditor1.Value, RadSpinEditor1.Value)
        button.Name = "btnDelete_" & (count + 1)
        button.Text = "test"
        RadLayoutControl.Controls.Add(button)

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Aug 2019, 01:53 PM
Hello, Obi, 

All controls that are added at design time are stored in the Designer.cs file. This ensures that when you run the project and show the form, these controls will be loaded and shown as well. There is no automatic mechanism for storing the controls that you may add at run time. You need to implement such a custom functionality according to your custom requirements. You can iterate the controls you have and produce a custom XML file with the internal structure that you will store the information for restoring the controls back on the form when running the application.

After some research in general programming forums, I have found the following threads which may be useful for serializing dynamics controls on the form:
https://stackoverflow.com/questions/32187309/saving-dynamically-added-c-sharp-winforms-controls
https://social.msdn.microsoft.com/Forums/windows/en-US/a42a54b0-f308-465f-9b4e-8dd09c600569/how-to-make-dynamic-button-permament-to-form-though-application-restarts-in-vbnet?forum=winforms

Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

Thank you for your understanding.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
obi
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or