Navbar control docking in split container panel1 - c#

I am creating new dynamic navigation panel without using GUI. I have Split Container consist of panel1 and panel2. And also creating new navigation bar.
I try to do Navigation bar control object should be docking style as fill in split container panel1.
SplitContainerControl splitContainerControl1 = new SplitContainerControl();
splitContainerControl1.Dock = System.Windows.Forms.DockStyle.Fill
NavBarControl navBar = new NavBarControl();
this.Controls.Add(navBar);
navBar.BringToFront();
navBar.Dock = DockStyle.Fill;
How do I fix this problem?

I have found another solution via different perspective and adapted to my code. here is the code if someone face this problem.
The idea is simple. just you need to add navbar in splitcontainercontrol panel property as follow;
splitContainerControl1.Panel1.Controls.Add(navBar);
splitContainerControl1.Panel1.Controls.SetChildIndex(navBar, 0);

Related

UserControl inside Panel inside UserControl not working

I am having some trouble creating the template of my application :
I am making some dynamic parts of forms and I use a panel in which I include my User Control according to the choice of the user. The panel has the same size as the user control but it doesn't work at runtime. The panel in which the UC is included is inside another UC also.
I tried autoSize = true, fixed size and many things but I don't know why it goes like this. Any idea?
Some parts of my code to load the User Control :
UC_panel.Controls.Clear();
UC_ADDRESS uca = new UC_ADDRESS();
uca.Dock = DockStyle.Fill;
uca.AutoSize = true;
UC_panel.Controls.Add(uca);
My UserControl for the address
At runtime it goes bigger
Since you set
uca.Dock = DockStyle.Fill;
and also
uca.AutoSize = true;
(which is redundant)
it is possible that some other container has its AutoScaleMode set to Font and its font size is bigger.

c# toolstrip doesn't dock under menustrip

I have a menustrip that I create using the forms designer. I then want to programmatically add a toolstrip toolbar UNDER the menustrip. The reason is that this toolbar is a set of tools that I add as a plugin to the main application. As such, when the plugin is loaded, I create the toolbar.
When I manually add the toolstrip to the form using the forms designer, the toolstrip is correctly positioned under the menustrip. However when I add it programmatically, it snaps to the topmost part of the form, above the menustrip. Here's the code I use to programmatically add the toolstrip:
stereoBar = new ToolStrip();
stereoBar.Anchor = (AnchorStyles)(AnchorStyles.Top | AnchorStyles.Left);
//y location is set to 22, the width of the menustrip
stereoBar.Location = new System.Drawing.Point(0, 22);
stereoBar.Dock = DockStyle.Top;
stereoBar.Name = "StereoToolbar";
stereoBar.Text = "Stereo Plugin Toolbar";
stereoBar.ShowItemToolTips = true;
stereoBar.GripMargin = new Padding(2);
Controls.Add(stereoBar);
Is there anything simple I am missing here?
Thanks in advance!
As described also in this answer, when docking controls in a form the order in which you add them to the form matters; i.e. when adding multiple controls that all dock to the top, the last control that gets added will be the topmost.
So, because you add your toolstrip programmatically and your menu strip via designer, the designer code gets executed first thus having the menu strip always at the bottom.
I think there are three ways out of the dilemma:
First approach
As Hans Passant pointed out, the easiest way to get things into the right order would be to simply call
stereoBar.BringToFront();
right after you added it to the forms' controls.
Second approach
To circumvent this you could also also add the menu strip programmatically and do this after you added the tool strip.
Third approach
Another way out may be to add another container to the form (Panel or groupbox for example) via designer that also docks to the top that simply just functions as a placeholder where you add your tool strip to (so you do not add to the form directly anymore)

Is it possible to add more than one panel in same location

i'm using telerik control.
So i want to ask,
In winforms application ,Is it possible to add more than one panel in same location and display one at a time just like show/hide property.
Make sure you have placed all panel control in same container or form. then you can use Visible property to show and hide panel. BringFront and SendToBack function will be used to bring panel on top or send it to back. If you have placed any panel in another panel then that will be disappeared when you Hide parent panel. So, Make sure all panels' parent control must be same. To determine the parent control simply select that panel and press escape key to select their parent.
private void LoadPanels()
{
panel1.Location = new Point(10,10);
panel2.Location = new Point(10,10);
panel3.Location = new Point(10,10);
panel4.Location = new Point(10,10);
panel5.Location = new Point(10,10);
VisiblePanel("panel1");
}
private void VisiblePanel(string panelName)
{
string[] panels = new string[]{"panel1","panel2","panel3","panel4","panel5"};
for (int i=0;i<panels.Length;i++)
this.Controls[panels[i]].Visible = (panels[i] == panelName);
this.Controls[panelName].BringToFront(); //Not required you can remove this line.
}
Here's a slightly different approach you might want to consider...
Are you wanting to be able to programmatically select the contents of a rectangular area at runtime, selecting among various controls to display? If so, you could use a custom TabControl which has its tabs (not the pages) hidden.
Then you can select which page is displayed by programmatically changing its SelectedIndex property at runtime.
Doing it like this means that your form editor will show a normal tab control, which allows you to much more easily add the content to each page - but at runtime the tabs will be hidden from the user; they will just see the contents of the currently selected page.
See Hans Passant's answer here for how to create such a custom tab control.
(However, you might also want to override the OnKeyDown for the custom tab control in order to ignore Ctrl-Tab.)

C# controling a panel

I'm using microsoft visual c# and making forms. I don't know if my vocabluary is correct but the idea is that when i create a panel using Panel Figure = new Panel ();
I cannot control it, i.e. change location. when I try
Point MoveLeft = Figure.Location;
MoveLeft.Offset(-25, 0);
Figure.Location = MoveLeft;
it requires already existing panel named "Figure" and my newly created panel doesn't respond to commands.
also is there any way that when I create a panel, it's an already existing panel i.e to create the same panel as panel "triangle"?
If you already have a Panel on your form called "triangle", you can simply reference it in code like this
triangle.Left = -25;
If you create a new Panel you need to add it to the Form's Controls list
Panel Figure = new Panel();
Form1.Controls.Add(Figure);
Form1.Location = new Point(-25, 0);

How to prevent usercontrol fill option from extending too far

I have a usercontrol that I'm adding as a control of a main form dynamically. The Mainform is basically empty, except it has a large status bar on bottom.
Problem is, when I set the Dockstyle.Fill option on my usercontrol, the size of the loaded usercontrol extends beyond the statusbar (It fills the entire main form as if the status bar wasn't there).
How do I prevent this behavior? This is an example of how I dynamically load my form
logicForm = new LogicForm();
this.Controls.Add(logicForm);
logicForm.Dock = DockStyle.Fill;
I think you need to set the DockStyle to None and use the Anchor property instead.
Set the anchor to Top,Bottom,Left,Right and size your control to fill all the space up to the status bar.
You should find when you run that the user control will then resize with the form.
I just found the solution
I need to bring the form to front in order to properly dock it if I already have some other controls on the main form:
logicForm.BringToFront();
Found here: http://dotnetref.blogspot.kr/2008/08/using-dock-fill-on-control-when-you.html
-________________________-

Categories