I have an application based on two user controls and one form. This form is parent to my 2 user controls and i pragmatically add them to the form. My issue here is that when anchor components in the user control, they are not anchored in the form. So when re-sizing the form by dragging one of the corners, it seems like the user control does not also get re-sized. I was told that i had to listen to the Forms size and append that size to the User control. Is that a good solution? if yes how would i do that?
My user controls are inserted in a tab component btw.
This is my code for adding the user controls to the form. (if it is needed)
public void addUC(UserControl control, TabPage tab)
{
control.Parent = tab;
}
can anyone help ?
You might want to anchor the child usercontrols using the Anchor property.
If there are only 2 use controls in the form why not use dock - it will always stretch the use control to the maximum size of the form
Related
I am trying to custom an editable container panel control like below in wpf.
The container panel control is an parent control that chould contains any other control and it is an editable control.It displays a plus icon with blank space when the panel control did not contain any control.User could click the panel which displays a plus icon to add any control to the panel.User could remove the control by floating bar which contains in the panel control.
Is there anybody could tell me what the name of this kind of control panel?And how can I achieve it in wpf?Any clue?
Thank you!
Try take alook at This,It should helps.
I am using c# drag and drop panels .the panels keep appearing and disappearing.Also i need help with panel box functionality words like "bring to front and bring to back" i think this is what is messing my panels up.What do they mean?
The Windows Forms Designer has a concept called Z-order. When two controls overlap, the Z-order determines which control will show up on top.
For example, suppose you have two controls called textBox1 and pictureBox1 on a Windows Form. Programatically, this refers to the Windows Form itself, Controls is the default list of controls in that Form, and textBox1 and is the actual control we are changing.
Selecting the menu option Bring to Front is equivalent to calling the control's BringToFront() method. This moves the control to the beginning of the default Controls collection of the Windows Form. So if you call Bring To Front on textBox1, it will show up above all other controls on your Form. Programatically,
// Bring the control in front of all other controls
this.textBox1.BringToFront();
Selecting the menu option Send to Back is equivalent to calling the control's SendToBack() method. This moves the control to the end of the default Controls collection of the Windows Form. So if you call Send To Back on textBox1, it will show up behind all other controls on your Form. Programatically,
// Send the control behind all other controls
this.textBox1.SendToBack();
You can also have finer control over the ordering programmatically. There is no way to do this in the UI. So:
// Put the control at the 2nd index in the Controls collection of this Form
this.Controls.SetChildIndex(this.textBox1, 2);
This page Layering Objects on Windows Forms gives some more details.
The page Windows Forms Controls: Z-order and Copying Collections has examples on how to control Z-order programmatically.
I have a pretty simple winforms application. It contains a rich edit box, embedded browser, progress bar, a few buttons etc.
I have the anchors on the controls set to expand in all directions.
When expanding up and down, however, the controls will overlap one another. How do I prevent this from happening?
Thanks
Your best bet is to add a TableLayoutPanel to your form which contains the "layout grid" this should be docked to the form, then you can add your controls into the cells in the table (they can cover multiple rows and columns so you can get the layout you want).
You must set the property Autosize=true on every control, especially on the main form.
Note that some controls like TabControl have this property, but you can't see it with intellisense (Attribute Browseable=false).
I have created a Windows form using a Tab Control, but it has a header with it. I want to hide it. I am not able to do it using any properties of the Tab Control. Is there any property defined for hiding the tab header for the Tab Control without going through the code?
Use following code to hide the tabs or set these properties in design.
tabControl.Appearance = TabAppearance.FlatButtons;
tabControl.ItemSize = new Size(0, 1);
tabControl.SizeMode = TabSizeMode.Fixed;
You want the tab panels without the feature allowing a user to switch between them, so I suppose you want to create few separate sets of controls to be shown to the user one at a time. You can achieve this in several ways (you can choose one of them if you find it appropriate in your case):
Use several Panel controls instead of several tabs in the TabControl, however, it would be hard to work in the designer, because all the controls would be visible
Use different Forms instead of tabs to keep the layout parts separated. It can be ok, but you may not want to use multiple Forms, so it depends on a specific case.
and finally, the suggested solution:
Encapsulate each set of controls in a UserControl. This allows you to keep each layout separately, so you can easily design each of them without the other controls getting in the way ;). The the code handling each of the layouts would also be separated. Then just drag those controls in the Form and use set their visibilities appropriately to show the one you want.
If none of those suggestions work for you, let me know, so I can look for other possible solutions.
It's more easy as you think, you just drag the panel's window upper, so will be outside of the form.
Use DrawMode: OwnerDrawFixed will hide TabPage header text DrawMode : OwnerDrawFixed
Another way to achieve the same (or similar) is: You can remove tabs from TabControl.TabPages collection and then add the tab you want to show.
During the Form initialization I remove tabs (so into the designer I can easily manage them) and in some control event (as button click) I show the tab the user has to see.
Something like that:
// During form load:
ctrTab.TabPages.Clear();
// ......
// During button click or some other event:
if(rbSend.Checked)
ctrTab.TabPages.Add(pgSend);
else
ctrTab.TabPages.Add(pgReceive);
In this way the user can still see the header tab but just as title of controls group, he can't change/switch the current active tab.
I am using a Panel to hold a list of controls (user-defined). The way that I add the panels, I am setting the location of the control based on the Panel.Controls.Count before I add it to the panel.
comRec.Location = new Point(comRec.Location.X, panel1.Controls.Count * 25);
panel1.Controls.Add(comRec);
Now, this works nicely and looks exactly the way that I want it to. However, once we reach the limit on the window, the AutoScroll enables (which I do want). Now, if the user were to scroll to the bottom of the Panel, this ultimately changes the location of every control in the panel. Instead of my first comRec.Location being (0,0), it is something like (0,-219). So now, when the user adds another comRec object, it creates a HUGE gap between the objects.
My question is this, what is the best way to account for the changes of the location with the scrollbar and still using my adding system. I am assuming that will have to do something with checking the value of the scrollbar and using it to determine the location.
Also, is there a BETTER way to display a list of controls? Should I be using a Panel?
Look at the FlowLayoutPanel control, it's exactly what you what.
You could add an additional panel into the hierarchy:
Outer panel (scrollable)
Inner panel (not scrollable, resize it whenever you add a control)
User Defined Control 1
User Defined Control 2
User Defined Control 3
User Defined Control 4
...
This way, your additional controls' locations would be relative to their direct parent, the non-scrolling panel.
If you add several controls, try to suspend the layout of the panel while adding the controls:
panel1.SuspendLayout();
// Add controls ...
panel1.ResumeLayout();
This helped me in a similar situation where the user could change dynamically the visibility of existing controls.