How to easily duplicate a Windows Form in Visual Studio?

前端 未结 14 1424
梦谈多话
梦谈多话 2021-01-30 21:03

How can I easily duplicate a C#/VB Form in Visual Studio? If I copy & paste in the Solution Explorer, it uses the same class internally and gets messed up. How do you do it?

相关标签:
14条回答
  • 2021-01-30 21:36

    Its Really Easy. "In Design mode FORM" (form1.cs[Design]) copy the whole Form "ctrl A" then ctrl C. All objects at once. Then add a new windows form to the project. Change the size of the form to the size that you want then paste ctrl V all of the new objects will be copied to the new form. When they are all still picked double click on any of the objects. NOT THE FORM!!!..... This will create the code on the Form side matching the objects you just pasted. if it doesn't you can double click on each object and it will create the code one at a time. I use a text box area to double click in and it works almost every time. I use this method everyday WORKS GREAT.

    0 讨论(0)
  • 2021-01-30 21:37

    First of all, if you're duplicating a lot of forms with cut and paste, consider a common base class for your forms (or for a category of your forms) that implements shared/common functionality or look & feel elements. You can also create a template for new forms that meet your needs and create new forms from that template.

    Personally I just cut and paste then fix any lingering name errors. Since I abstract out common functionality, I have not felt enough pain to look for a better way ;-)

    0 讨论(0)
提交回复
热议问题