why are new controls showing up in my form AND panel - c#

i have a form with a few controls on it, i have a panel with different controls on, That panel is above the form controls.
i have added new controls to the form and when i place the panel back over the form, the new controls are showing through the panel itself, but only the new one controls and not the "old" ones, if i copy and paste a control or add a new one it has the same effect.
i have looked in the designer.cs and the new controls are being added to the form and NOT to the panel itself.
this is weird and iv checked various properties but cannot immediately see the reason for this.
i have made MANY forms before and this is the 1st time this is happening.
one the note of controls, is there a way to change the default value of the labels "AutoSize" property from TRUE to FALSE; i'm using visual studio CE2015
any ideas on what to check? im really stumped by this one.

As mentioned in the comments, you need to check the z-order of your controls.
In the picture below you can see a form I created with two buttons and a panel as you were describing. Neither button is one the panel, however button 3 has a z-order that puts it on top, just as the panel is on top of button 2
If you right click on the controls you want to change the z-order of you see Bring to Front and Send to Back. Choose the appropriate option.

Related

Create controls dynamically or create controls in a side form? C# winforms

I have a form full of controls, and there is no room for other controls. On the bottom of the form I have a panel with some controls on it.
My goal is that when a certain button is clicked, the original panel on the bottom will be replaced with another panel that contains controls which could be created before the program starts, meaning these controls in the panel do not need to be created dynamically. The replace action would be executed by setting each panel's visible field to it's matched value.
I have thought of two ways of doing this - either creating the new panel (and it's controls) dynamically and adding it to the form instead of the original, or creating the new panel in another form and when the relevant button is clicked the panel being taken from that form and added to the required form (by creating an instance of the new form and making it's panel's modifier public). The "side form"'s purpose is only to create that panel, it has no functionality of it's own.
The advantages of creating the new panel dynamically:
There is no need to create a zero-functionality form.
The advantages of creating the new panel in a side form:
It's very clear which controls are added to the new panel and their positions.
It's very easy to set the location and other fields of the controls in the new panel.
Which way is better?
Thanks!
Have you considered TabControl? That seems a good fit for your needs. Other controls I can think of are StackPanel (Can be fairly easily done for Windows Forms) or OutlookBar like control (again a user control).
Simplest and quickest way seems to be TabControl.
Edit:
SideForm is a different windows form I suppose. So if you are thinking to make controls public and then change their visibility etc, please don't. Use delegates to handle SideForm's events in MainForm.
As you mentioned, there is no room for more controls, I would suggest more screens rather than just one. Having said that I do not know much about your current UI design and functionality so it's up to you.
I would say having the controls hidden and just playing with the Visibility is fine. This means that you do not have to worry about positioning of controls, anchoring and docking at runtime. The problem could well be loading of form. Having huge number of controls having a lot of data associated with them may slow things down.
IMO the best way would be to utilise user controls for this purpose. Simply create one user control per panel you wish to show/hide and place your controls inside. This way you will have both: the designer and the "extra form" you wanted.

Inconsistent behaviour when attempting to highlight C# TextBox

I'm building a C# WinForms program, and my textboxes do not allow the user to highlight the text consistently throughout the program.
In some places, the highlighting works normally: you type something in the box, click and drag over some text, and it highlights where you dragged.
In other places, clicking and dragging does not select the text. The only way to do it is by double clicking on the text.
I haven't changed any default properties of these textboxes or messed with any event listeners. I placed brand new textboxes in different places, and they behave differently.
I'm wondering if it has something to do with the properties of the Form the TextBox is contained in, since it seems to appear that either all textboxes in a particular form work, or none do. However, as far as I can tell the properties look to be the same across the board, and I don't ever remember changing anything.
To me it seems like it's happening randomly. I can't find any information on the topic. Does anybody have any idea what I'm talking about?
EDIT: Ok, I figured out where the problem lies, but I still don't know how to fix it.
It happens only in forms which have been added to a SplitContainer in my main window like so:
myForm.TopLevel = false;
this.splitContainer.Panel2.Controls.Add(myForm);
myForm.Show();
EDIT 2: I now know that this is the same issue encountered here: Windows Forms: Unable to Click to Focus a MaskedTextBox in a Non TopLevel Form . The accepted answer isn't useful to me, and the other answers seem impractical, since I'd have to add event handlers to every single textbox...
I had the same problem today. I tried changing TopLevel as others have suggested. This didn't work. Somewhere along my search I saw a suggestion to create a click event for the text box and use it to force focus on the control. This made no difference either. There were no events that should intercept and block a click event. It was just an MDI child with a few controls on it stuffed inside a panel on a split container. I couldn't highlight text in textboxes or textbox-derived controls though.
Turns out the solution was to switch the order of childform.Show() and panel.Controls.Add(childform). If you add the child form before it is shown, you apparently cause this bug.
I'm a little perplexed at what you're trying to accomplish. I'm used to using a user control if I want to embed something on a SplitPanel, and using an MDI form if I want child forms.
Do either of these approaches work for you, and if not, can you explain why not/what you are trying to accomplish?
Thanks!
James
* Edit *
You can add a panel (regular panel, not a split panel) to an MDI parent form and dock it to the left. Add whatever you currently have in the left panel of the SplitContainer to this left-docked panel, instead. Now you can instantiate forms, set them as children to the main MDI parent, and have all the window functionality you're looking for... You can maximize them, and they will fill the right-side of the MDI parent; you can pick cascade or tile from the window menu, etc.
If you want to let the user dynamically resize the left panel, drop a splitter panel into the right-hand portion of the main MDI form container; it will dock left by default, and show up to the immediate right of the panel. Now when you run, you can drag the border of the panel to resize.
Remember, an MDI form is like any other form... you can add any control you want to its surface, and .NET is pretty smart about how it incorporates the child windows.
If you're still not sure of what I'm trying to describe, I'll try to find somewhere I can drop a sample project... because everything is really done in the designer, there's not really any code I can show you. Here's the code for creating a form as an MDI child (running from within the MDI parent):
MyForm frm = new MyForm();
frm.MdiParent = this;
frm.Show();
That's all there is to it.
HTH!
James

Managing Lots of Overlapping Controls in Visual Studio

I'm using different sets of controls on the same location on a form. By default all are visible=false and then certain subsets of the controls are set to visible as the user selects specific values in a combobox dropdown control.
From the user's perspective this works well since they only see the controls that are needed.
However, since the controls occupy the same location on the form it is difficult to manage these in Visual Studio design view.
Is there a way to group sets of these overlapping controls in Visual Studio so that I can select the entire subset of controls quickly and easily? Is there a way to hide certain controls in design view? Right now everything is stacked on top of each other when developing so it makes managing these controls difficult.
To get such a beast to work i would put every group into it's own UserControl. On your MainForm you stack all these UserControls above each other.
So at the MainForm you can't really get a good overview, but now you got for every group your individual designer view and in your main form you can hide the complete group by a single line of code userControl.Visible = false.
A TabControl can do this, works well in design mode. You just need to hide the tabs at runtime. Check my code in this thread.
You can not hide them.
However you can group them in group box
and using "Bring to front" and "Send to back" property deal with them.
First of all,
If you work with multiple components in same location, you can use groupboxes in your form. Then, to superimpose these groupboxes, you should edit each of your groupboxes on different place in your form screen. After the edit, you should input size and location data manually in your groupbox properties menu.
If you want to edit one of your groupbox after the set location, you can easily right click any of your groupboxes then click "send to back" and "bring in front" commands. I hope it helps.

How do I create a banner panel in C#?

I want to create my own custom control that is basically a TableLayoutPanel with 3 rows and 1 column. The top and bottom rows will contain labels (banners) and the middle row is where I will add other controls. The problem is that when I try to build other forms/controls from this control, the designer doesn't recognize the middle panel. How do I get it to? If I drag a textbox to the middle and set Dock=Fill, it will cover the entrie form/control. Also, is there any way to get the designer to reject dragging of controls to the top and bottom (banner) rows? I've tried the steps in the following link but haven't had any luck (http://support.microsoft.com/?scid=kb%3Ben-us%3B813450&x=21&y=15).
I figured it out. The trick was to create my own designer that inherits from ParentControlDesigner and overrides the Initialize method and calls EnableDesignMode for the inner content panel. On top of this, I needed to set the Designer attribute of my user control to this new designer. The details are shown here.
One problem, though. I can drag controls to the content panel I created and everything looks fine. But, once I recompile, the controls disappear. They are still there, I just think they're getting drawn before the banner panel. I will create a separate thread for this problem.

Why are controls within custom panel (C# winforms) disappearing in designer?

I have been able to create a custom C# winforms control that is basically a panel with a fixed banner (header/footer). I want to base other user controls on this "banner panel". I've gotten past the problem with the designer here. I can successfully add controls to the inner content panel. Everything looks fine while designing. However, when I recompile, the controls I added to the content panel disappear. They are still there (in code) but aren't displayed in the designer. Is there any thing that I need to do to set the drawing order of the controls?
Your controls are still nested correctly within the panel control, they have just lost their z-order. If you choose the controls from the property panel and right click on the control border that appears within the parent panel and select "Bring To Front" from the layout toolbar, your nested controls will re-appear. I don't know why it does this, but a workaround is to bring all child controls to the front during control initialization in the code.
There is really nothing to go on here without src. What I would do is to comment everything out including in the InitializeComponent function but a widget in the middle panel and run. Do whatever it takes to get that one widget to show. Inherit from UserControl instead of the banner panel.
Then comment in each piece until the widget no longer comes up. That is what is causing your problems. Once it all comes up properly, then you make sure the designer portion of the src works. It is going to potentially be a long process.

Categories