Separate class TabPages - Windows Forms - c#

I am a beginner in C# and Windows Forms, and I am trying to make a little application to manage different databases.
To do so, I would like to have a TabController with different TabPages, one for each database.
I already have a template of what will be inside of the TabPages, and I want to replicate it for every TabPage. So I would like to have a C# class for every TabPage so I can just copy/paste the template and change the data source.
The problem is Forms keeps creating Partial classes when I try to create a new form, or won't let me create a class binded to my TabPage.
Is there any way to have a TabPage have its own code ?
Thanks in advance.

Create a UserControl containing your database UI and a public "DataSource" property. Then, place one of the user controls on each tab page.

Related

WPF: Selectable usercontrol - How?

I’m new to C# and WPF and have a problem I hope you can help with.
I have a WPF application with a stackpanel to which I add usercontrols by code to display the information stored in an instance of a class. The user can create instances, and musty be able to edit and delete instances of the class by selecting the usercontrol. The usercontrol contains a canvas for making a simple sketch as part of the information stored in the instance.
My problem is: How do I make the usercontrol selectable, so that the user can select an instance for editing or deleting, and so that I can address the canvas by code in a particular instance?
I hope you can help me.
/Morny

Make dynamically number of tab pages with ZedGraph in WinForm C#

I have data for several days. I want to plot that data, one day in one tab page. The tab page can change dynamically corresponding with the number of the day.
Previously, I always make a static page in the design mode. I use ZedGraph control to plot the data. I decided how many pages that I need. Then it means the number of pages is static.
Now, I need more dynamically. I want the number of tab pages can change dynamically. Each page has similar controls inside it. How to do that? I have no clue about it.
First you create a new class of type UserControl. These are meant to act as containers for controls. Then you put everything on it you need in your typical tabpage including the ZedGraph control..
Also write your logic there.
Now, when you need another page you create one and add a new instance of the UC class you have created.
You should think a little about dependencies with the rest of you application, including the deleting of the pages; a page controller class comes to mind that can handle these things, if necessary.
You could also subclass a tabpage but going the UC way gives go an additional layer of independency; you could place the same UC on a form or inside a container control..

Best way to display groups of data in one form?

I am looking to create a windows form. This form is to display groups of data separately and I was aiming to do so in the same form window rather than have multiple windows open.
For example each group of data is defined by a Job#. A user will want to review X different Job#'s at a time (Range would usually be 1-5, but could be more). I would like to have 4 dataGridViews for each Job# plus various identifying and summed data in text boxes. Initial Example Concept
I was looking into using TabPages/Tab Controls. My initial idea was to have a user click the different tabs to view the data for those jobs that they have pre-selected. However these tabs don't seem to behave like classes from what I can see. Is there perhaps a better way to go about this or some way to have the tabs act like classes? So that each tab has a Job TextBox, 4 Different DataGridViews, etc. So that I can easily create and display any number of jobs?
For example each Tab would have 4 dataGridViews, maybe 8 Text Boxes, Standardized Labels and a Standardized layout.
So would using tabs be a good idea? Using some other WinForm control?
There are at least 2 solutions here:
Create a custom Panel holding all the controls you want (TextBox, DataGridView, ...), design it so that it looks best to you. Then add each of that Panel to each of TabPage of your TabControl.
Create a new custom TabPage and add the custom TabPage to your TabControl.TabPages instead of the standard TabPage.
I think the second approach can be done if you can initialize everything using code (not by drag-n-drop) because to get the drag-n-drop supported, you may need to write a custom TabControl. So the first approach is feasible and OK. You can replace the Panel by a Form, set the Form.TopLevel = false, you can add that form to any container control. Using Form, you can benefit the easiness of drag-n-drop to design and organize your controls.
Here is a little of code which may help you figure out:
public class TabPageClient : Form {
public TabPageClient(){
InitializeComponent();
Dock = DockStyle.Fill;
TopLevel = false;
FormBorderStyle = FormBorderStyle.None;
}
//.... other code
//I think this is important
//You should define some Properties and methods to control the data flowing into and out from your TabPageClient.
//You can also support some method to add/remove the controls dynamically.
}
Take the drag-n-drop requirement into account, I think using UserControl may be better:
public class TabPageClient : UserControl {
public TabPageClient(){
InitializeComponent();
Dock = DockStyle.Fill;
}
}
For UserControl, you should place the class in a separate *.cs file, compile your project and then you can see it in the ToolBox window (at the very top). Just drag and drop it like as other controls.
Personally, I prefer grid-detail views. Something we make heavy use of in our software. The form has a SplitContainer in vertical alignment.
In the top panel, you add a list of some kind (ListBox, ListView, DataGridView...any control into which you can load a list and then react to selection).
In the bottom panel, you have yet more options. Simplistically, you could use a TableLayoutPanel and then setup rows/columns to provide whatever arrangement of embedded controls you like, such as your array of grids to display data. I suppose in keeping with your model, you'd have a single ColumnStyle and four (4) RowStyles. Then in each row, add a grid.
This way, you keep it all in one place...one "screen", if you like (no tabs to flip through). You react to the selection in the list to decide what data to display in the grids. You then just need a bit of code (a class I would hope) that interfaces between the class(es) that provide the data, and the form controls that display it (the grids).
An additional benefit here is that with the list presentation, you can have a lot more than five (5) jobs in play at any one time. In fact, with scrolling, as many as you like (not limited to the number of tabs before the display goes to pot).
Also, you would be re-using the grids. Simply refreshing the displayed data for the list item selected. You could even pre-load and cache it all if freshness is not an issue.
Also consider binding directly to data source if that's an option.

Rendering User Control in Windws Phone 7

I'm new to windows phone 7
I want to ask for your help in some code for:
Im developing and app which has multiple pages. Now I want to put it into a single page using some user control. For example my main page will have a company logo in a grid and a second grid which is empty. The second grid should display the UserControl in which i'll ask user to log in, after log in I want to display another UserControl for some list box and all. Trouble is I'm not getting how can I display and change user control in Page? Just like partial page in asp.net MVC.
Is there any function which gets executed every time user control is changed, like asp.net MVC has "OnActionExecuting". Can we create a UserControl as BaseUserControl and inherit each UserControl from it...is it possible????
Sorry I'm very new to this windows phone.
I'll try to give you some hints and code to manage your problems.
First. It is possible to do all what you want ;).
If you want to use only one page (possible not the best practice) you can change your Ui from code. If you have your Page, with MainGrid and two Grids, inside MainGrid. You can access each grid with the x:name property, you had set in xaml.
Example:
<Grid x:name="MainGrid">
<Grid x:Name="LogoGrid"/>
<Grid x:Name="ContentGrid"/>
</Grid>
Here you can add your userControl as following:
var control = new CustomUserControl();
ContentGrid.Children.Clear(); //maybe delete old Children
ContentGrid.Children.Add(control);
Handling the Events is also easy. Just build it into your UserControl, like a LoginButton and replace the old UserControl with the new one after ButtonClick.
You can simply change the user control by adding the user control as a child to the container Grid.
MyUserControl myusercontrol = new MyUserControl();
mygrid.Children.Add(myusercontrol);
or to remove,
mygrid.Children.RemoveAt(0); //if you have just one child control.

The proper way to use dynamic tabpages in C#

I am developing a simple software in .NET C# for blind people that includes a phonebook.
The phonebook consists of a form with tabs in it (each tab represent a group i.e. family, friends , work etc.) and in each tab a listview that will contain the contacts in that group.
The groups are of course dynamic and user made.
My question is what is considered the proper way to handle the tabs? To create a new listview for every tab or one for all of them? how to handle the different list views? should I redefine every time the characteristics of the listview for every tab?
Would appreciate an example.
Thanks.
The best way would be to have one listview (your main list view) and then a tabcontrol which will be the host for your tabs (this is called tabbed MDI interface) .
you can create separate forms for each one of your main entities (family,friend,work,etc.) and then based on the clicked item in the main list view you can open (or activate) related tab in the the main tabcontrol .

Categories

Resources