I'm working with a GUI in PowerShell and trying to make the form such that, after the form is built, the user can interact with the part of the form (+/- button) to dynamically add a group of controls to the form underneath of the existing set.
As an example, there will be a combobox (drop-down) to select a parameter and then a text field to fill in the value for the selected parameter.
What I'm looking for is a way to dynamically add that group of controls to the form when the user clicks the plus button. My current attempts have failed. I've tried pinning the controls inside of a TableLayoutPanel and a Panel object but can't seem to get the items to appear in the first place and then appear in some semblence of order. Is there a GUI object that I can pin the controls to that will just auto-dump the next row of controls below the existing or do I have to figure out the calculations off of the docked parent and offset the Y-values?
Does anyone know a PowerShell accessible Windows form control that would support this type of additions?
One of my attempts is psoted here: .NET 4 (WinForms) Dynamic Form Control Creation in Powershell
Any help is greatly appreciated.
Maybe you could use FlowLayoutPanel. Here is the sample script for using FlowLayoutPanel in Powershell
It's not Winforms, but there is a new module up on Codeplex called ShowUI, which enables you to create WPF based UI's in PowerShell. Take a look at http://showui.codeplex.com. There is some examples up there on using Grid controls and automatic layouts, that I think could meet your needs if you are willing to jump into WPF.
Got the answer from a Microsoft PowerShell forum Moderator:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/b2c8abeb-3ae6-4936-9bef-a50a79fdff45/
it's the datagridview object that needs to be used.
Can't you simply build your form (for example with Sapiens free editor tool) with all the controls invisible, and then according to the user choice make them visible ?
Related
I am working on a WinForm based applications(Yes I don't know WPF) and want's a dashboard like panels in it. Picture given below
Each panel will have a title and records from Database and some action controls. How could this be achieved? I don't want to use GridControl as I don't want to show Excel like spreadsheet here. How could this be achieved?
It sounds like you want to make a UserControl, possibly coupled with an automatic layout panel like FlowLayoutPanel.
Simply speaking, you would create a UserControl with whatever properties and events you require (i.e. in your example you might have a Title property and a Data property), and any events you need to respond to (e.g. you might have a button that you provide a wrapper event for). Then you can add the control to your existing form as you would any other standard control.
As far as displaying data in list form goes, one suggestion is to use a Panel and dynamically add Labels to it. Another idea could be just a simple Label with line breaks in the Text.
Can someone suggest the best way to achieve my goal?
So, I have a form with three buttons. What I want is, depending on what button is pressed on panel should be shown different controls (user control). I made this in a simple way: all are added from the beginning, I just make change to the visibility. But what would be nice is, if someone can suggest a more appropriate way, because there is no need to have objects created from beginning.
You can always create the appropriate UserControl, and add it to the Panel.Controls at runtime. This will allow you to create the control(s) as needed, instead of on initialization of your Form.
I would indeed create the controls at design time - if there's advantage no to dynamically create them. Why complicate matters?
If there are a number of controls I would put them all in a panel (within the panel you've already mentioned) so you're only changing the visibility of a single control (the panel) rather than each one within it.
When you press the appropriate button show the appropriate panel (and remember to hide the others in case you've previously shown them)
ALL,
I am trying to develop a C# Windows Forms application.
For that I needed to make a custom control that is derived from the GroupBox.
Now for the problem.
I have a form and on the form I put a grid box. On 1 cell I put a GroupBox and on another cell I put my custom control.
For both controls properties I put "ColumnSpan" to be 3 as grid has 3 columns.
The native control display itself properly, meaning it is stretched.
The custom control display itself incorrectly, meaning it is not stretched.
I checked and all properties in the properties inspector are the same.
What am I missing?
Thank you.
For some reason custom controls do not resize themselves. So all I had to do in the GUI designer is to resize the control.
Thank you for reading and hopefully it will help someone else.
I have a combobox in my winform, and I wish change the button that show the list (with the triangle) with another button or at least change the image..
it's possible? how can I do this?
thanks!
you should use OwnerDrawn techniques like the one described here: https://stackoverflow.com/questions/2891981/net-ownerdraw-combobox-vista-7-themed-dropdownlist
or you override the window proc and redefine whole control message handling or you create your own control from scratch or you use third party controls like DevExpress WinForms suite or Telerik ones.
I have a section of a form where the controls (text boxs, labels etc) need to be built at run time depending on options a user has selected. There will probably be about 7 - 10 different layouts in all.
What's the best way to go about creating and maintaining them?
Cheers
Luke
It would be helpful to know more about the specifics of your situation (what kind of options are we talking about?)
But off the top of my head, I'd guess you probably want to create a set of Panels which would contain the appropriate controls then hide or show them depending on the options.
I have actually had to do just this. I did it with a set of panels (as #David suggests) and also a TreeView. Using the tree view, I customized the visuals to make them mimic an options menu in Microsoft Office, and then I show the appropriate panel based on the user's selection of nodes. If you'd like to see code samples let me know.
All WinForms controls has corresponding classes (Button, Link, EditBox etc.) You can create any controls you want and attach them to form.
Inside the form Init you can add new controls into Controls collection.
public void Init()
{
this.Controls.Add(new TextBox());
}
Some more details in MSDN:
http://msdn.microsoft.com/en-us/library/0h5y8567.aspx