-
Jan 9th, 2019, 08:28 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to Duplicate a Panel with it's all controls?
So my project is something like Trello but program but with some special editing made for my work needs.
I made one panel with all needed controls and codes and I also changed the names of controls to be sorted if needed.
this video shows me moving this panel as a (To Do card) from location to other location on form.
https://streamable.com/s/f4dz8/hhgwvc
this yellow card is a Panel that I want to duplicate or copy past or whatever gives me another same Panel or as it should be named (Card).
Is there a way to generate another copy of this panel in run or design time and it does the same things where it should get the same properties and behave as the first panel coded?
any good idea for this situation as I need to make 50 same Panels at least?
-
Jan 9th, 2019, 08:42 PM
#2
Re: How to Duplicate a Panel with it's all controls?
Don't use a Panel in the first place. What you should have done is created a user control. You add a user control to your project, design it and add appropriate code in pretty much the same way as you do a form but, once you build your project, that user control is added to the Toolbox and you can then use it like any other control. You can add multiple instances to your form from the designer like you would any other control and you can create instances at run time like you would any other control. It's just like any other control.
That said, if you really want to stick with the Panel, which I recommend against, then you simply Ctrl+drag in the designer, the same way you copy a file in Windows Explorer or copy anything else that supports similar drag and drop operations.
-
Jan 9th, 2019, 09:07 PM
#3
Thread Starter
Hyperactive Member
Re: How to Duplicate a Panel with it's all controls?
Originally Posted by jmcilhinney
Don't use a Panel in the first place. What you should have done is created a user control. You add a user control to your project, design it and add appropriate code in pretty much the same way as you do a form but, once you build your project, that user control is added to the Toolbox and you can then use it like any other control. You can add multiple instances to your form from the designer like you would any other control and you can create instances at run time like you would any other control. It's just like any other control.
That said, if you really want to stick with the Panel, which I recommend against, then you simply Ctrl+drag in the designer, the same way you copy a file in Windows Explorer or copy anything else that supports similar drag and drop operations.
Fully understood.
I will try this and see
Thank you very much
-
Jan 12th, 2019, 06:33 PM
#4
Thread Starter
Hyperactive Member
Re: How to Duplicate a Panel with it's all controls?
Okay that worked fine
I Added the a UserControl that user control has no panel and I manged to move it by mouse in run time then I added this control twice on the same form and worked fine each usercontrol was moving separately with no interference.
The only problem is when I bounded the textbox in that user control to the (Application Sittings) all other controls from the original one have the same string and are behaving the same as the original one.
How I can bound those text boxes to a diffident string?
This video might help understanding the problem
https://streamable.com/s/xrl4f/ccjvwk
-
Jan 12th, 2019, 07:03 PM
#5
Re: How to Duplicate a Panel with it's all controls?
Where did you do the binding, in the user control or in the form? If you did it in the user control then of course every instance uses the same value, just like if you do it in the form then every instance of that form will use the same value. The proper way to approach this is to make all the child controls Private in the user control and then add a property to the user control for each child control property you want access from outside. For instance, you have a TextBox in the user control and you want to access its Text property from outside then you should add a property something like this:
vb.net Code:
Public Event TextBox1TextChanged As EventHandler Public Property TextBox1Text As String Get Return TextBox1.Text End Get Set If TextBox1.Text <> Value Then TextBox1.Text = Value OnTextBox1TextChanged(EventArgs.Empty) End If End Set End Property Protected Sub OnTextBox1TextChanged(e As EventArgs) RaiseEvent TextBox1TextChanged(Me, e) End Sub
In the form, you can now bind that property to a setting for a specific instance of the user control, just like any other property. The event is necessary because, otherwise, the Binding won't know that the property has changed and that it needs to update the setting.
-
Jan 12th, 2019, 08:22 PM
#6
Thread Starter
Hyperactive Member
Re: How to Duplicate a Panel with it's all controls?
Originally Posted by jmcilhinney
Where did you do the binding, in the user control or in the form? If you did it in the user control then of course every instance uses the same value, just like if you do it in the form then every instance of that form will use the same value. The proper way to approach this is to make all the child controls Private in the user control and then add a property to the user control for each child control property you want access from outside. For instance, you have a TextBox in the user control and you want to access its Text property from outside then you should add a property something like this:
vb.net Code:
Public Event TextBox1TextChanged As EventHandler Public Property TextBox1Text As String Get Return TextBox1.Text End Get Set If TextBox1.Text <> Value Then TextBox1.Text = Value OnTextBox1TextChanged(EventArgs.Empty) End If End Set End Property Protected Sub OnTextBox1TextChanged(e As EventArgs) RaiseEvent TextBox1TextChanged(Me, e) End Sub
In the form, you can now bind that property to a setting for a specific instance of the user control, just like any other property. The event is necessary because, otherwise, the Binding won't know that the property has changed and that it needs to update the setting.
Great it Amazed me how easy it was
but there is something is not going very well
when running the application with three instances and start changing the text inside textboxes it seems like letters get deleted very fast or not written at all.
and here is a video of what is going on and what I did:
https://streamable.com/s/lkmto/dsfzor
-
Jan 12th, 2019, 08:47 PM
#7
Re: How to Duplicate a Panel with it's all controls?
I just ran a quick test and I had no such issue, but it didn't seem like the entered values were being saved. I don't have time to test more thoroughly right now but I'll have a closer look when I do.
-
Jan 13th, 2019, 07:00 PM
#8
Thread Starter
Hyperactive Member
Re: How to Duplicate a Panel with it's all controls?
I really do appreciate that.
Thank you very much.🙏🏼
One more thing I noticed:
While trying to solve the problem I deleted all instances from that UserControl on the main form and kept only one instance.
I noticed it worked fine alone.
So adding more instances is making the problem in my case.
-
Jan 13th, 2019, 07:53 PM
#9
Re: How to Duplicate a Panel with it's all controls?
I realised why my settings weren't being changed. The code I provided would update the setting if the user control property was set in code but the TextBox1TextChanged event was not being raised if the user entered text into the TextBox via the UI. Without the event, the setting cannot be updated. My code would have to be modified like so:
vb.net Code:
Public Event TextBox1TextChanged As EventHandler Public Property TextBox1Text As String Get Return TextBox1.Text End Get Set If TextBox1.Text <> Value Then TextBox1.Text = Value OnTextBox1TextChanged(EventArgs.Empty) End If End Set End Property Protected Sub OnTextBox1TextChanged(e As EventArgs) RaiseEvent TextBox1TextChanged(Me, e) End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged OnTextBox1TextChanged(EventArgs.Empty) End Sub
Last edited by jmcilhinney; Jan 13th, 2019 at 08:02 PM.
-
Jan 13th, 2019, 08:07 PM
#10
Re: How to Duplicate a Panel with it's all controls?
FYI, I just tested my new code on a form with one TextBox and three instances of a user control containing a TextBox and all four controls were bound to settings and I could successfully enter text in each one, close the app, run the app again and see the text restored.
-
Jan 13th, 2019, 08:56 PM
#11
Thread Starter
Hyperactive Member
Re: How to Duplicate a Panel with it's all controls?
-
Jan 13th, 2019, 09:02 PM
#12
Re: [RESOLVED] How to Duplicate a Panel with it's all controls?
I can't think of anything that would cause the symptoms you described off the top of my head. I can only suggest that you make changes to your test project to make it more and more like your existing project and see if and when it breaks.
-
Jan 13th, 2019, 09:09 PM
#13
Thread Starter
Hyperactive Member
Re: [RESOLVED] How to Duplicate a Panel with it's all controls?
Originally Posted by jmcilhinney
I can't think of anything that would cause the symptoms you described off the top of my head. I can only suggest that you make changes to your test project to make it more and more like your existing project and see if and when it breaks.
Doing now
Really Happy to solve this and many problems on this great Forum.
Thank you very much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|