How do i add another components on the MainWindow? - c#

Struggling, I need a button to open up a window but below the MainWindow in C#. Like in a website you can open other pages but the master page layout doesn't change only the page you are viewing shows differently.
I need similar thing. I have components (tools i added from toolbox) on my MainWindow.xaml so for example if i click on a button i named new student, a tabbed-window where i can capture student details must appear but it must not be a separate windows it must appear within the mainwindow and seem like a one thing. Forgive for my English. I hope someone will understand me though, thanks in advance. I want to have components/functionality according a specific button click but constant Mainwindow, the one with "File" "Edit" "View" "Help".

There are a couple different solutions to you problem, but Visual Studio doesn't quite have something like the Master View option through ASP .NET with webforms.
Option One
Using TabControl. This option is the easiest solution to your problem. The GUI in Visual studio has support for adding components to each tab, which nothing else has. This is the closest component to something like multi-panels in Java, but it will still create the Tabs, which may not be what you are looking for.
Option Two
Using multiple Panels over one another. With this option, you can add multiple panels to your main window and layer each panel over one another. You can add a button or other control which will hide each panel and all of its contents. This is a great solution if you don't want tabs, but it can be frustrating to create in Visual Studio since you must move each panel away from another in order to add/remove/adjust the components on the underlying panel.
Of course there are still a few more controls you can use to produce the results you are looking for, but these are probably the most applicable solutions to your problem.

Related

Mimicking Visual Studio "Properties" Tab in C#

I'm creating a simple WYSIWYG editor for HTML in C#, and I want to implement a simple group of controls to view and manipulate the various properties of HTML form elements. I envision the properties panel to look like the one in Visual Studio:
Such that when the user clicks on an HTML element they've added they can change the text, class, id, etc. of the element. The problem is, I can't find how to make a panel that looks like this using C#. Obviously I know how to implement the dropdown list and the buttons, but the main body that actually contains the properties is like a slick version of a tree-view that I don't even know where to begin coding.
I'm not looking for someone to code this whole thing for me, but it would be great if somebody could point me to a form control that looks like the tree-view. I have tried googling around for answers but haven't had any luck. I have also tried looking at the open source project Sharp Develop which uses a similar control, but I've had considerable trouble wading through the hundreds of files of code to find the specific part of the GUI I'm focused on.
Any help on this would be greatly appreciated. Sorry if I was a tad bit vauge above, I guess what I'm really looking for is a nice form control or set of controls in C# to mimick the main body of the properties window. I've tried to be as thorough as possible, but if you have any questions leave a comment and I'll try to improve my question.
The body of that panel contains a PropertyGrid control, which you can use yourself. It's not in the Toolbox by default but you can add it.

Organizing code in c# using 1 Form and a lot of functions

I am writing a program that has like 8 tabs in one form. Each tab does different functionality so as you know it requires a lot of methods/variables/classes/background workers etc..
I used to write similar programs before but the MainForm.cs file had a lot of code and it made it very messy( a lot of controls, on click events, etc..)
What is the best way to organize the code in such case?
Are there any documents or examples to follow?
Please let me know!
If everything HAS to be in one class, I'd try partial classes out. You can make a new .cs file for every tab and add it to your project, but everything will still be in the same class.
http://msdn.microsoft.com/en-us/library/wa80x488.aspx
Create user controls for each tab page and place all control in their separate user control for each page. Thus, your code will be separated in their usercontrol. You can also invoke their method and handles it's events from your main form.
The best solution I've found is MDI Child Forms. Each tab can be created as a separate form then added during initialization. I also believe you can drop these into a tab form, see here.
Good luck!

Navigating between parental panels

I have problems with editing panels in C# windows forms(Visual studio 2008). I placed some panels into another, and now I have problems with navigating panels inside parental containers. Is there any tool that gives not only drag-drop control, but also tree view of container and panels in it. For example, like Navigator window in NetBeans(IDE for Java). Any help?
I'm not sure about VS2008, but newer versions have Document Outline Window (View > Other Windows > Document Outline)
To not get lost in controls, consider to name them properly. Then you can find them in the list of Properties window.
Instead of label1 use labelInputName, located on panel1, which you also rename to panelInput. This gives parent/child feeling and you will never lost.
If you get lost, use Document Outline window to see tree-like relation via Controls property (who is control of who). This window is a helper (help to find and select control), you will still have to use designer to do changes.
Another important thing is UI design. Whenever you get cluttered or bulky feeling, than it's the time to change something.
Making UserControl for repeatable part is one way.
Another is to differ design and run time (what you see in designer): to example, if you have several panels, which has to be shown at same place, then you can use dynamic container for them (FlowLayoutPanel, TableLayoutPanel) or you can have them placed in a way for you to easily see them in design-time, but their position will be corrected during run-time (to example, in the constructor). Prioritizing designing is a must if you are going to support project and edit functionality in next versions.
p.s.: talking about winforms, but all said should be true for wpf as well.

Force visual tree creation with Prism

I have a TabControl containing Prism regions. I want to trigger some kind of notification (e.g. flashing the tab header) for certain events, and I want to trigger this notification from the components in the Prism regions.
Once the tab containing such a component was open once, this works nicely using VisualTreeUtil.GetParent() and going up until I find my TabControl and can modify it to indicate the notification.
But the problem is that this doesn't work until the tab is opened by the user because VisualTreeUtil.GetParent() returns null; obviously because Prism doesn't hook up the visual tree until then.
Calling UpdateLayout() on the TabItem containing the region doesn't help. I don't want to open the TabItems programmatically, because this would confuse the user.
Is there anything I can do short of implementing a kind of region registry (which would be rather ugly and harder to maintain)?
If you want to look at code, I wrote a minimal solution to demonstrate the issue. The Print Structure button tries to go up the visual tree from the (initially unrendered invisible) hello TextBlock on the second tab. Before you switch to the tab it prints only the TextBlock, afterwards you get to the root of the visual tree. This is what I want to accomplish without switching to the tab.
Adding comment as answer:
This probably isn't exactly the answer you are looking for, but it seems like you're taking a very procedural approach.
Have you considered using an MVVM approach? Each TabItem in the TabControl can have a HeaderTemplate. In the template you can bind to a property in the ViewModel that causes the tab to flash or change appearance
Hm.. IIRC Prism regions are just a configured ContentControl/ContentPresenter. Once they are ready to work, all the bindings and datamodels should be in place, but the trees are left not created because they are invisible. If so, you should be able to call ApplyTemplate() on them to force it. I do not remember, however, if the Prism assigns the contenttemplates/datacontexts upon init, or upon demand - the latter may cause calling ApplyTemplate useless.

Is it good practice to stack multiple user controls on top of each other?

In my C# class, we use Visual Studio. My teacher says it is really not good practice to be stacking controls or panels on top of each other and hiding and showing them when needed. They say it should all be kept to separate forms. However, this puzzles me. I can understand that if you are in design mode, it is a little strange to see all these controls on top of each other, but you edit them all separately, so I don't see the issue. I think its really odd to be closing and opening forms like that and it looks a bit strange to the user.
Say you had an application in which you wanted to use multiple controls on top of each other. Say for example it was a login/register form and you didn't want to use a tab control, for whatever reason, and you wanted buttons in the menu strip to switch between the login or register user control, wouldn't it make sense to simply hide/show user controls?

Categories

Resources