What is the bottom space on the Windows Forms design view? - c#

I'm trying to learn about Windows Forms Application. Now, as I was creating a DataSet, Binding source, Table adapters. I noticed they show up on a bottom section on the design view. My question is: What is that section, and what goes in there?

From MSDN:
Non-visual components added to the Windows Forms Designer are placed on the Component Tray, located below the design surface, so that they are easily accessible without cluttering the visual design space.

This section generally corresponds to nonvisual elements in a Form, but which are stil relevant to the Form, such as a Timer.
Since they're nonvisual, it doesn't make sense to put them in the designer with the visual elements, but they still need to be in the designer for the designer to be useful in setting their values.

The bottom part of the winforms designer is used for non-UI elements. Things that are created / generated just as fields in the class behind, and not added to the actual view.

Related

c# Binding windows forms controls in designer without typing any code

I need to bind two controls (pictureboxes) in my c# windowsforms designer (using Visual Studio 2015) so when I do an action with the parent one (for example hide it), the child will also hide... but on the other hand, when i hide the child, the parent will stay the way it is...is there a way to do this just in the designer without typing any code?
I couldn't find any answer on the Internet.
Thank you.
There's no way of doing this in the designer. You will have to implement this behavior using some code.

Navigating between parental panels

I have problems with editing panels in C# windows forms(Visual studio 2008). I placed some panels into another, and now I have problems with navigating panels inside parental containers. Is there any tool that gives not only drag-drop control, but also tree view of container and panels in it. For example, like Navigator window in NetBeans(IDE for Java). Any help?
I'm not sure about VS2008, but newer versions have Document Outline Window (View > Other Windows > Document Outline)
To not get lost in controls, consider to name them properly. Then you can find them in the list of Properties window.
Instead of label1 use labelInputName, located on panel1, which you also rename to panelInput. This gives parent/child feeling and you will never lost.
If you get lost, use Document Outline window to see tree-like relation via Controls property (who is control of who). This window is a helper (help to find and select control), you will still have to use designer to do changes.
Another important thing is UI design. Whenever you get cluttered or bulky feeling, than it's the time to change something.
Making UserControl for repeatable part is one way.
Another is to differ design and run time (what you see in designer): to example, if you have several panels, which has to be shown at same place, then you can use dynamic container for them (FlowLayoutPanel, TableLayoutPanel) or you can have them placed in a way for you to easily see them in design-time, but their position will be corrected during run-time (to example, in the constructor). Prioritizing designing is a must if you are going to support project and edit functionality in next versions.
p.s.: talking about winforms, but all said should be true for wpf as well.

Which one is better generating controls(labels, textboxes, listview, buttons etc) on runtime or creating layout in c#?

I am working on my final year project, in my project i am using winform c#. My project is some sort of security system including hardware.
In my project I have a lots of controls like panels, textboxes, labels etc. Till now I am using layout and it is getting slower and slower (and flickering more and more) as I am adding more controls in it.
My question is that isn't it better to generate controls when required and destroy them when I don't need them? Will it save memory?
Assuming that you use the VS Windows Forms Designer, it will create the code for you which will be loaded at runtime. There will be no difference if you load the controls in Form.InitializeComponent (as the Designer does) or in any other place where you wrote it yourself. The only thing the designer does is it creates the Form.Designer.cs file for you while you design the form, and you can use those controls the same way you would use the controls you create at runtime yourself.
Loading a lot of controls on a single form is not a good practice. And it will get slower as you add more contols. You should probably consider redesigning the GUI.

Show dynamically created controls in Windows Forms designer

Is there a way to see controls which are created via code in designer instantly but not only during execution?
The Windows Forms designer only applies properties contained in the automatically generated file "Form1.Designer.cs" (example filename for "Form1"). If you change properties (e.g. text, color, whatever) or create new controls in your own code, i.e. in "Form1.cs", the designer does not show it.
It is practically impossible because the designer would have to either 1) parse your code or 2) execute it to apply all changes to the controls.
Option 1 does not work because expression evaluation only works when running the code... Which leads us to option 2: Letting the designer running your code to find out dynamically added properties? First of all, automatically running untrusted code is not what you want. Second, there must be a reason that you do these changes dynamically instead of statically in the designer, so showing dynamic changes as WYSIWYG does not even make sense.
The designer can only display controls that exist at design time or show example controls for databound controls. If you think about code that would dynamically at runtime create a textbox or label based on a variable, how would the designer know which one to display in design mode?
If you have specific logic for how you want your dynamically created controls to display in design mode, you would have to create a custom control and implement the design time drawing code. This is mentioned under the Custom Design Experience heading here: http://msdn.microsoft.com/en-us/library/ms171725.aspx

Modify Visual Studio's form designer code generator

I'd like to basically control the name of the method that the Visual Studio form designer uses for putting it's generated code in. By default, this is named InitializeComponent. But often times I need to have different layouts for different types of screen resolutions/aspect ratios (see Designing forms to work on different resolutions and aspect ratios on Windows CE for more detail). That way, at runtime I can choose how to layout the form by calling the appropriate one.
I realize that there is likely no trivial way to do this. I assume I'll need to build a custom VS add-in and extend the existing forms designer and hook into the code generator and layout interpreter for this to work properly. Any ideas on where I could start looking to make this happen?
Can you not switch within InitializeComponent and call different layout logic methods according to what platform you are?
if(platform.IsCE)
{
CELayout();
}
else if (platform.Tablet)
{
TabletLayout();
}

Categories

Resources