Question How to Show/Hide this Control/form

geerizzle

Member
Joined
Oct 14, 2013
Messages
5
Programming Experience
1-3
A text box on my form does live web searches, returning up to 10 real time as-you-type results. I have this populating a datagridview with a couple of columns.

My question comes in terms of how to display this. I can set the gridview to show/hide ok, likewise set its position. But where to put it while it's hidden? No room on my form, especially where it needs to show above other controls.

I have got round this by adding the grid to another form, showing this where I want it and making it stay in front. But if I minimize my program that form is still there... not ideal.

I suspect a better way is to add the gridview at runtime, but I am unsure to what object controls to add it to. i.e. if I add to main form controls how to I get it to display where I want it & in front of everything else?

I'm sure there is a simple answer here! (PS I'm not using the MS auto complete as I need a couple of columns to show)
 
But where to put it while it's hidden? No room on my form, especially where it needs to show above other controls.
When the control is hidden it takes no space on form, it can be placed anywhere. When you need to show it you may also use the BringToFront method for it to appear over other controls that has same location. You can also use "Bring to front"/"Send to back" with context menu in designer to help with configuration/layout.
Placing controls added at runtime is done with Location/Size properties, or both with Bounds property.
adding the grid to another form, showing this where I want it and making it stay in front. But if I minimize my program that form is still there... not ideal.
For this layout you can set the owner of the form, and it will minimize/restore along with its owner, and also stay in front of its owner like dialogs/tool windows. Three ways to do this:
  • set form.Owner
  • add it to owner forms OwnedForms collection
  • use the Show method where you specify owner
Typically you can also set ShowInTaskbar for such a form to False, so only one window for your application shows in Taskbar.
 
That's great thanks, I hate having forms with controls on top of each other it makes it hard to edit so I'll go with setting form ownership etc.
 
I hate having forms with controls on top of each other it makes it hard to edit
No it doesn't. You simply use the Document Outline Window to select a control and you can right-click and select Bring to Front or Send to Back to see the one you want.
 
^ Yeah precisely... I like just being able to see it, not have to mess about sending things backwards and forwards, especially with multiple layers.

IMO when it's like that it defeats the purpose of using a visual designer you might as well just do it in code
 
IMO when it's like that it defeats the purpose of using a visual designer you might as well just do it in code
IMO that's complete rubbish. It only takes one mouse click to access a control that's hidden another; two if you want to actually see it in front of the other, which isn't even necessary to change it's properties. Are you really saying that that is as much extra work as it would be to create and configure all your controls in code? I've worked on apps where I've had multiple Panels stacked on top of each other and each had multiple child controls. That would have been a real chore to do in code but was very simple using the Document Outline window. I didn't even get tired making the few extra clicks required.
 
Back
Top