what is the best replacement for TabPages - c#

if one part of one form of our app has many views - let's say depending on a radio button selection some where else on that form - then sometimes using a TabControl with some tabPages can be easy and helpful to show different views based on that selection.
so I still would like to have that "multiple views" functionality but I do not want to use a TabPage.... what would be the best replacement for that?

As far as I know, you'll have to code such a control yourself if you desire a lot of functionality. For regular operations, however, you can use this control I found on CodeProject: Multipane Control.

You could just have a Panel or something to define the area and then you could create one User control for each "view" that you want and then when the user selects a different radio button you just shows/hides the relevant user controls inside that Panel.
Or if the "views" are very simple, maybe the User controls would be overkill and you could just have a GroupBox for each view that you show/hide, but that can quickly create messy code if there are lots of event handlers etc.

Related

Dashboard controls in Winforms

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.

I am looking for a specific control panel

I am looking for a specific control panel to contain the 3 gridviews that I have. The user should flip through the gridviews (preferably with no postback). The controls of the flipping should be at the top of the panel. What "control panel" can I use to achieve that aim?
If i understand correctly what you mean with "flip", you could use an ASP.NET Ajax TabContainer to organize the GridViews in different TabPanels. With ASP.NET-Ajax you could also load the TabPanels/GridViews asynchronously and also only if visible.
Here are some tips.
Lazy-Load TabPanels
TabContainer: Tips&Tricks
Well no postback means client side, and there's no better way to do this than with javascript!
If you would consider using jquery/jquery ui, then the ui tabs are probably what you are looking for.
So now you could create a custom control containing all 3 gridviews, and hide/show them using tabs

Building Controls at Runtime

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

How to implement a-form-inside-a-form with runtime embedded forms switching?

I need to implement TabControl-like behaviour with manual (on event, on a button click for example) pages switching and having all pages designed and implemented as separate forms. A form to be incorporated (as a panel control) inside main form and replaced by another form as needed.
How to achieve this?
PS: The reason why I don't want to use TabControl instead is because there are going to be too many tabs - I'd prefer to present the list of them as a TreeView and instantiate on demand. The another reason comes from another project of mine - there I am going to implement plug-ins, where a panel inside main window will be provided by a class loaded dynamically and will be runtime-switchable.
I need to implement TabControl-like behaviour with manual (on event, on a button click for example) pages switching and having all pages designed and implemented as separate forms
May I ask why this is a requirement? It seems like the logical approach would be to create a set of UserControls. You can place a UserControl in a form, and you can place a UserControl in a tab. You get modularity without the headache of implementing a very odd requirement which is a use case that the API developers obviously did not think was valid. I just can't think of a good reason to take the route you have suggested.
I did similar thing once, and for that reason, I have ReplaceControl method, which I paste below:
static public void ReplaceControl(Control ToReplace, Form ReplaceWith) {
ReplaceWith.TopLevel=false;
ReplaceWith.FormBorderStyle=FormBorderStyle.None;
ReplaceWith.Show();
ReplaceWith.Anchor=ToReplace.Anchor;
ReplaceWith.Dock=ToReplace.Dock;
ReplaceWith.Font=ToReplace.Font;
ReplaceWith.Size=ToReplace.Size;
ReplaceWith.Location=ToReplace.Location;
ToReplace.Parent.Controls.Add(ReplaceWith);
ToReplace.Visible=false;
}
Only thing left to do is to create some control manually on the form, as the placeholder for your Form. Use label, for example.
You could do this with an MDIForm as the main form, and then plain-old Forms as the separate forms. Or you could encapsulate each element's functionality as a UserControl which you can then swap out on your form in code.
The advantage of encapsulating your UI elements as UserControls is that if, for whatever reason, you need them to become forms in your application, you can just drop the UserControl on a form.
Update: Since you want to use a TreeView to select what the user is looking at, you definitely want to do this as a bunch of UserControls. The layout is simple: TreeView on the left, and whichever control is active on the right.
There's no need to justify not using a TabControl - tabs are the worst UI element in history.

C# Winform Question

I'm just getting started with winforms in C# and things are going well, except I want to learn how to do something like:
if user presses "proceed" button, it will run some code, and change the form, so that there are more options available to the user on the form. In other words, I want to make my forms more than one "page". I hope that all makes sense. Any help would be appreciated, thanks!
You could have a tab control with separate tabs that you move through that are disabled until they are needed. Each one could have its own controls, etc... You could have the controls disabled on the main form and then enable them, etc... There are myriad ways that you could approach this problem.
For winforms:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Visible = true;
}
One easy way of doing that is to add a container control, for example a GroupBox that contains a selection of controls that belongs together and then you make that GroupBox invisible. Then in the button click handler you make it visible again.
That way all the related controls are shown/hidden together and if needed you can move them around the screen without needing to worry about their locations related to each other.
I want to make my forms more than one "page"
When I do that, I normally build each "page" as custom control. This let's me separate the navigation elements from what it is you're navigating to, so that I can easily play with different ideas later. For example, do I want to use a tab control to host each page inside a separate tab? No bid deal - just drop one my controls on each tab. Swap out different pages on the same form? It's only one control to replace. Move between completely different forms? Still easy.
As a basic starting point, if you want to run some code when the user clicks the button just handle the Click event. Just double click the button to get to the code-behind and place your code in there.
In terms of exposing extra functionality when the user clicks proceed there are various options available to you, its really up to you to figure out which is best suited to your application. One simple option would be to perhaps have a Panel or GroupBox and place all the extra options on there and make it disabled, then enable when you see fit.

Categories