I need to dock a WinForms user control at run time but I'm encountering an issue.
In my main form, I have a menu strip at the top of it. I want to programmatically add a UserControl docked to the left of the main window and below the menu strip.
When I add my User control at runtime and then set its Dock property to DockStyle.Left, it does not appear below the menustrip but instead it takes up the entire left side of the form. This causes the menustrip to be pushed to the right and does not look attractive.
I need to do this at runtime because the project requires the ability to customize which user control can appear on the left side of the main form for each user.
Any help in finding an answer would be greatly appreciated.
A quick and dirty way to do it would be to add a Panel beneath the MenuStrip (docked Left or Full), then add the UserControl to the Panel.
Edit: What's happening is that the order in which controls are added to a container determine how they will appear on the form. Since you're doing this programmatically at some point after the form has been created, the UserControl is the last Control added to the Form, so it's going to affect those items already on the form. If you have a Panel on the Form that makes things appear as you want them too, adding the UserControl to the Panel will only affect those items inside the Panel and not on the rest of the Form.
Add an Panel which docks below the toolstrip, and add the User Control to that container.
Edit: Already answered.
Related
I've bundle of control save in .vcx file but I need to activate it to display it when i switch to different activepage in pageframe.
Could anyone guide me how to code and which kinds of event should i make on page frame switch, click or whatelse UIENABLEEVENT.
Thanks.
First, you might want to click on Help -> Tour for site etiquette and start voting / checking your answers so people know what worked or not that help you and others with similar issues.
Now, back to you question... If you have a form with a pageframe, make sure you have the "Properties" sheet open, it helps to ensure which object you are actually working with until you get more familiar with the IDE.
Once you click on the pageframe control, if you right-click and then select "Edit", that will bring you to the individual PAGE level of the pageframe. Once the PAGE is the basis of the focus you can put any control on it from either the toolbar, or if your project is open and you expand your .VCX class library, you can grab any control and put in on the page.
If you have multiple pages, once you click on the alternate pages, you will see that the first page (or whatever page) is no longer visible and the new page is available for you.
The actual handling of the pages on the pageframe for clicking / focus is automatically handled for you unless you want to do something extra.
and thank you for viewing my thread. I have a project I am creating in Visual Studio 2010 with C#. It is basically a Word minutes template. I have a form that the user fills out, which then goes to the word document. I have gotten stuck with a problem. I will try my best to explain. I have a section where the user keeps entering data on a subject. I need to be able to have the form continuously populate the same panel until the user clicks the check box which moves the user to the next question. Right now, I have the panels on top of each other and have them hide until the user checks the checkmark and moves on. My problem is that I have no idea how many possible panels will be needed. The user could have only 5, or the user could have up to 100 if needed. Is there an easier way to have the form populate panels automatically? I will attach a screenshot below. Thanks for all the help!
I have to modify an old VB6 program that uses ActiveReports 2.0 at work and I am having some problems (BTW I have never used this program before and only have a basic knowledge of VB6)...
I have to make some text boxes biggers which is pretty easy to do but as soon as I move them a whole section of text (and not simply the content of that text box) disappear.
I have noticed that it was in some sort of section (sorry, I don't know how they call that) which englobed those text boxes so I made it bigger and that made no difference.
What could be causing this?
Thank you!
Nick
It sounds like the TextBox is inside a UserControl. A UserControl is created by a developer, and is basically one control with any number of other controls in it. You can check to see if there are any User Controls in your project in the Project Explorer (Ctrl+R).
One way to know exactly what class the control belongs to is to open your form in design mode (Shift+F7), click on the control, and look at the Properties window (F4). The drop-down list should show the currently selected control's class name in bold, then the name of the object.
What is the control's class? If it is anything other than TextBox, then this would explain the unexpected behavior you experienced.
how can i find the specific button on design mode where i have several buttons ie: hundered of buttons so that they all like spaghetti and one button may be under another button or a groupbox (i might be playing with the visibilities ) and i want to see my button number 83 on the design. how can i see him? where is he hiding? :) i use visual studio as an IDE. thanks.
MessageBox.Show(" where is the specific button? i know that he is somewhere on the form but cant distinguish it on the design since its somewhere under something i cant find it");
Use Document Outline (View - Other Windows - Document Outline)
Just pick the button from the tree and voila.
PS: this works for other types of designers (WPF/Silverlight, ASP.NET)
You can access it via the Properties Window. There is a drop-down that will list all of the items in your form in design mode.
Then use the drop-down. The drop-down will list all of the items on your form so you will scroll through the list to find Button number 83.
Images were pulled from MS Visual Studio: The properties Window which contains an explanation of the window.
Have you tried using the properties window?
I inherited the prototypical corporate application with a person form (with address, phone, etc).
Now on that mentioned person form one label+textfield is a child of the form itself and not of the panel it visually belongs to.
How can I change a control's parent from form to an existing panel in VS 2008 designer?
Update:
Ah, it seems to be a problem with the super magic custom group box control my beloved cow orker left for my pleasure. Dragging into a normal group box works ...
Update 2:
With the help of the Document Outline I can see that the custom "GroupBoxExt" we have in the application is defective, dragging a control onto the panel (or just changing position of a control on the panel) assigns it to the form.
Update 3:
Now that I new what was wrong (thanks for the document outline tip) I went of to google and found a custom group box on CodeGuru. The author of that artilce found out you'd need to decorate your custom panel with
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
to make it behave as a nice container.
If you're looking to do this in the designer, what you're looking for is the Document Outline panel (it's under the View menu under "Other Windows"). From there you can drag controls by their name in the outline and reassign the parent.
Hope this helps!
I'm not sure exactly what your asking. Can you try clarifying the scenario a bit?
But if you want to change a controls parent, all you need to do is make that control a child of the panel using the Controls property.
myPanel.Controls.Add(target)
This should update the parent of target to be myPanel.
If you're attempting to do this via the designer, all you need to do is drag the target control onto the panel and that should take care of it.