Adding TabControl to Form with Exisiting Controls - c#

In WinForms C# using .Net 2.0 I want to add a TabControl to a Form that has existing controls. Is there a way to move all the controls into a tab control without Visual Studio blowing away all my event handlers the like? Using Visual Studio 2005.

Yes, make the form as large as possible and draw a tab control on the right side of the form. Then select all the controls on the left side and drag them on the tab control. Now your event handlers will remain intact and controls will be placed on the tab control nicely.

I would select all of the controls on your form, hit Ctrl-X (cut them), put the TabControl on your form and make it as big as you need, then hit Ctrl-V to paste all of the controls into the TabControl. This will maintain the state of all of your controls..you won't lose event handlers or anything.

Related

Can't see a button in designer

I'm on Windows 10, maintaining a C# Desktop application using Visual Studio 2019, putting controls onto a Form (System.Windows.Forms.Form). I'm attempting to change an application; reworking where the controls go etc., so there is code and control design that I want to keep and put into different locations. I am using the visual designer and connecting to code using the control events (as opposed to creating the forms dynamically).
I have Document Outline visible on the left; I cut several groups of controls I intend to paste back later, so all that one particular TableLayoutPanel has in it now is two buttons. But I cannot find those buttons in the designer. I can see them in the Document Outline; they're in a TableLayoutPanel (in a group box in another TableLayoutPanel on a TabPage, etc.). When I click on a control in the Document Outline, the corresponding control is usually highlighted in the View; however, when I click on either of these buttons, nothing is highlighted in the view.
I tried resizing the Form (which determines the sizes of all these panels/tableLayoutPanels set to 'fill'); it's currently at 1367,850; one of the button locations shows as 664,752, but I don't know in what coordinate system that applies. I tried manually setting the location to 50,50 in the properties window, but it won't let me change that there.
These buttons appear at the bottom of the form; they've never appeared there, but I've noticed sometimes the designer has shown dotted-line outlines of them outside the form entirely. They appear in place when the application is run.
I've tried changing between the 100% scaling and the 125% scaling; that didn't help. For two buttons, I suppose I could delete them and recreate them, but there are many, many controls on this UI, and if there's some trick to making things appear I'd like to know about it.
Is there a trick to this that I'm missing?

Custom TabControl - Adding Controls with Designer

Long story short, I created a custom winform TabControl:
public sealed class MyTabControl : TabControl
And I can't find a way to add other controls to its TabPages. When I drag and drop any kind of Control (a Button, for example, or a Panel) on the top of a TabPage display area, it's added to the Form instead of being added to the page itself. Anyone can explain me why and how to implement Designer interaction to my custom Control?
First you have to add your "MyTabcontrol" to tool box.
How to do that:
On the Tools menu, click Choose Toolbox Items.
On the .NET Framework Components tab, click Browse.
In the Open File box, locate the DLL that was built when you created the UserControl control.
Then Drag UserControl from the toolbox to Form.
Then it works.
Here is the KB link from Microsoft.
https://support.microsoft.com/en-us/kb/813450

Reusing screens created in compact framework?

I've created a screen in compact framework using the form editor, is there a way I can grab this screen or at least some components of it and use them in multiple places in the compact framework app?
Yes, tcarvin is right, just create a user control and then reuse this in your compact framework application as often as you need.
To start right click in VS on the project name in solution explorer:
In the popup menu click Add and then UserControl. Accept or change the file name for the user control and then you are looking at the empty user control:
You can now resize the user control canvas and then place other controls as buttons, labels, textboxes etc. on it:
You can then also enter code for button events etc. In the example one can add code to use openfiledialog to select a file and the filename will then displayed in the textbox.
When you are ready, you have to build your solution to get an updated control list on the left in visual studio. Back to a window form design view, you can then place your usercontrol:
Is that simple?
You can also build a library with user controls and then reuse your controls in every compact framework project where you reference the library.
~josef
It sounds like you need to look at UserControls. They let you create add one or more controls to a surface (the UserControl), and then you can add that UserControl to as many forms in your application as you want.

design panel without parent form in Visual Studio

Anyone come up with a way that I can design a panel without a form?
On the surface usercontrol doesn't seem the way to go.
Background:
I come from a text editor world and VS is new to me. We did everything with panels instead of forms. So open for learning. Specifically have a base class panel (ExtendedPanel) that defines some basic controls: Cancel, Save, Save and Close. This ExtendedPanel then will be used for ClientExtendedPanel that is tied to a bindingsouce clientBindingSource. This is all tied to my entity framework model. So I will add, edit and delete sql datarows for my Client table. If no changes have happened by Save button will not be enabled. If I make a change but hit cancel it will warn me. I've done all this before but since I left that company I don't have access to the code base and they didn't use VS (text editor only)so it wasn't really transportable anyway.
All that background so I can ask: Is usercontrol the way to go, or is there something that will allow me to visually add controls to a panel like it is a form?
Yes, a UserControl provides a form-like canvas in the designer for you to add other controls (buttons, etc).
You can do this too by inheriting a panel and writing the code to add the buttons and wire their events, etc, but you won't get the designer support.

Create Visual Studio style Options/Settings Dialog

I am currently in the process of improving my options dialog for a winforms application. At the moment I am using a tab control.
I would like to create a form/dialog for settings that is similar to Visual Studio's. How is this done? I can see a treeview like control on the left hand side but what control are they using to display each of the options pages, it doesn't appear to be a tab control. I would like to be able to build the controls for each of the settings at design time.
Thanks.
They look to me like UserControls. I can't say how exactly they implement it, but it would be simple enough to build a UserControl for each option type and swap out the current control when the tree view selection changes. In your designer you would simply have the TreeView and a parent panel to host the UserControls. At runtime you would perform the swap.

Categories