I'm a bit new to the C#-form app developing and I want know, what's the best way around at making a control that holds a list of horizontal items. In which each of these items are horizontally ruled to it's parent control, contain a thumbnail to the left and a large text block to the right of image and a smaller text block underneath that. So basically this isn't a predefined control I can find in the toolbox. Any ideas?
You could lay this out with Panels in form controls, or with WrapPanel and StackPanel in WPF.
In WindowsForms, I would create a user control that held the correct layout for a single item, then make a list of them at run time.
In WPF I would use a List control, but set the layout template to use WrapPanels and StackPanels.
WPf is the better solution long term if you don't have to coexist with winforms
Related
I want to create a UserControl that displays a dropdown selection control and a couple of buttons when collapsed, but could be expanded to display a larger selection of items when desired. It's expansion panel should slide down over the controls of the Window or UserControl it's embedded in.
I can do it if all of the XAML is in the same control, but I can't figure out how to do it if I want the small view and sliding bits in a separate, re-usable, UserControl.
For a small panel I am using an animation that changes the margin of an offscreen panel and bounds clipping to make it happen. I have been copying the XAML from Window to Window. I want to make a re-usable much larger version of this, but displaying it, properly, has me a bit lost because of the bounds clipping. The UserControl clips the panel within it's smaller view, rather than allowing the panel to display over it's parent.
This is the effect I am looking for:
The primary issue seems to be that the sliding panel has to be contained within the UserControl, or it gets cut off. So the user control has to be much larger than its collapsed view. Because of that, when you want to embed it in another Window (or UserControl) you have to do XAML gymnastics to accommodate for the size of the control while making appear that the control isn't really that big.
Maybe that's just typical for XAML. I am still learning. But I can't figure out how to have a visual element of a control appear outside its bounds. A Popup doesn't really work because of how it opens and closes with focus.
At this point it's just an exercise, as I've decided to implement it a different way (modal dialog) so I have the control I need over the visuals.
I'm certain this can't be as complex as I'm finding it so far!
I'm trying to render a horizontal list of user controls. There will be a large number of them. So some form of Virtual list would be prefereable.
Each user control will contain an image and be selectable.
In Android/Flex/iOS this is trivial with their List Adapters, List Item Renderers etc... However in Win forms it seems very tricky indeed.
I've looked at ObjectListView setting the view mode to Tile. However there doesn't appear to be a way to render horizontally.
I've tried just populating a flow layout with my user controls. But the memory usage goes through the roof as it's loading images.
You could use FlowLayoutPanel container control and set its WrapContents to false and FlowDirection to LeftToRight (which is default). ...and, probably, AutoScroll to true.
EDIT
As to going out of memory, think of simulating virtualization by handling Scroll event and creating/disposing controls as needed.
Derive your own image control from Control and override OnPaint in order to draw the image yourself. Add a property for the path or name of a picture, but don't store the image itself in the control. Google for custom control c#.
Use a cache for the images. A good data structure for this is a circular buffer. This helps in keeping only a limited number of images in memory.
I have developed a windows Application in .Net2010 in Windows 7, Windows Forms and Controls looks Perfact in Windows 7, but in WindowsXP Text containing in Textbox hides first character overlaps between Label and Textbox as shown in Following picture:
The Label controls that you're using to provide a caption for each of the TextBox and ComboBox controls are extending out over the top of the TextBox and ComboBox controls. Their background color is the same as your form (the brownish-gray color).
One possible solution is to change the Z order of your controls so that the Label controls are always in the background. The controls will still overlap, but the TextBox and ComboBox controls will overlap the Label controls instead of the other way around.
That would work fine as long as there was no text on the Label controls getting covered up. That's rather unlikely, and you certainly count on it. Instead, you need to redesign your form so that there is plenty of extra space between controls. You can't jam things up that close to one another, or there won't be any room for expansion and they'll have no choice but to overlap.
Move the controls around and give them some breathing room. The aptly-named Padding property is very useful for this.
You could use TableLayoutPanel to place your controls in a good manner
Go here to read about it.
With this you could use Docking and Anchoring properties of those controls to grow or shrink them as the space changes.
My application (which I am using Visual C# 2008 WinForms for) involves a lot of generated controls. Specifically: grids of buttons, arrays of labels, lists, headings, etc... all populated so that they fit their containers appreciably.
I want users to be able to resize the main form, which obviously would require me to either destroy my generated content, and remake it at the proper size OR I could index through every control, figure out what it is by name and type, and re-size each item individually. I would have to do this while/after the form resizes.
Are there any more intelligent ways of doing this? Dock and Anchor don't quite apply here because I am dealing with items that don't make up 100% of a dimension (for example, grids of buttons).
Hard do give a reasonnable answer without seing just how complex the layout in question is.
But in principle, you should use a layout container such as FlowLayoutPanel or TableLayoutPanel to do the job they were designed to do. If one does not do the job, just nest them.
Docking/anchoring is probably the answer here. You need to anchor your grid to top/bottom/left/right or dock it (same effect, but the grid will fill the parent control).
If this is done right your control(s) will re-size with the rest of the form just as if you created everything in the designer.
I believe something like this would work:
Control.Anchor = AnchorStyles.TopLeft | AnchorStyles.BottomRight;
Using C# 2.0 what is the best way to implement dynamic form controls?
I need to provide a set of controls per data object, so should i just do it manually and lay them out while increment the top value or is there a better way?
You can use panels with automatic layout such as FlowLayoutPanel and TableLayoutPanel.
Unfortunately there are only 2 panels with automatic layout out of box but you can create custom layout panel.
I would recommend you to read following articles:
How to: Create a Resizable Windows Form for Data Entry
Walkthrough: Creating a Resizable Windows Form for Data Entry
Another option would be using of WPF (Windows Presentation Presentation).
WPF is a perfect match for your task.
WPF controls can be hosted in WinForms apps so you don't have to switch to it completely.
#Sam I know this question was about Windows Forms, but you should definitely start looking at WPF. This sort of scenario is really easy in WPF with DataTemplates and TemplateSelectors.
What do you mean by “dynamic”? A new, fixed set of controls for each data row in the data set? Then use a UserControl that contains your controls.
Or do you mean that, depending on your data layout, you want to provide the user with a customized set of controls, say, one TextBox for each column?
Yeah, I've found manually layout out controls (incrementing their Top property by the height of the control plus a margin as I go) to be reasonably effective.
Another approach is to place your controls in Panels with Dock set to Top, so that each successive panel docks up against the one above. Then you can toggle the visibility of individual panels and the controls underneath will snap up to fill the available space. Be aware that this can be a bit unpredictable: showing a hidden panel that's docked can sometimes change its position relative to other docked controls.
Well that's the way we are doing it right now on a project. but that's only useful for simple cases. I suggest you use some sort of template for more complex cases.
For instance I used Reflection to map a certain type of control to a certain property on my domain objects on an older project.
You could try generating the code from templates using t4 see T4 Templates in Visual Studio for Code Generation Screencast for a simple example. You can apply this to WinForms.
Also DevExperience has a nice ( expensive ) framework, see DevExpress eXpressApp Framework™ .