c# Custom Control Navigation - c#

I have a bunch of Custom Control Forms (i.e. login page, home page, etc.) that I want to be embedded within a "main form". Every time the user navigates to another page, only the content of the "main form" gets changed.
But the only way I can do this is to copy the contents of the Custom Controls and paste them into the "main form" - which is messy. Is there a standard way of doing this type of thing?

Update:
Ok it sounds like possibly you want to use an MDI form or maybe to use user controls (switching out controls for the new pages and such).
Old:
Is it possible you are talking about ASP.net pages and wanting to use master pages?

You might want to use a Panel. Put all the controls for each “embedded form” in a panel of its own. Then you can just show and hide the right panel to make controls appear and disappear.
Alternatively, if you want the user to be able to manually switch between the “pages”, you could consider using a TabControl.

Related

Recommended way to manipulate User Control panels into a Windows From

I just started working with Visual Studio C# and to be honest I didn't fully understand what happens when we chose to hide a form or a user control.
My intuition tells me this hide/show method is kind of "inefficient" way to get an user through all the functions of my app.
So I am asking you guys if there is another workaround to "load" user control parts in a form.
Right now my main_menu form has all the user control objects placed on the form, but hidden, and I am using buttons to show them.
Is there a better way to achieve the same result? (I was thinking of a workaround like having an empty panel where I can load the User Control - not sure if possible)
Thank you!
You can create the controls on the fly and add them to or remove them from the Controls collection. On the class level, define this field
private Control _currentPanel;
You can use a more specific type here, if you are deriving all your panels from a common base type.
Then change the panel with
// Remove previous one.
if (_currentPanel != null) {
Controls.Remove(_currentPanel);
}
// Add new one
_currentPanel = new MyNewPanel();
//TODO: possibly set the panels Docking property to Fill here.
Controls.Add(_currentPanel);
In the example I am working with the form's Controls collection; however, you might have to use the Controls collection of some container control holding the panel.

Cloning tabs in Tab Control on button click in Winforms

so I have a Homepage on one of the TabPages on winform TabControl. I have a button, that adds a new tab using this Tabs.TabPages.Add("Homepage");
But TabPages.Add() just adds a new blank page, how would i clone my HomePage on the new tab? For instance, if my homepage has a button "Click me", when i open a new tab, I want it to have the same button "Click me" linked to the same event "ClickMe_click". Like a Chrome Tab control. I couldn't find any event or method built in for TabControl on msdn, unless i missed it.
Any help or hint or suggestion would be appreciated. Thanks.
You can't clone a tabpage so easily. One can try but the recommended way is:
Create a UserControl and add all the controls you want on your page. Make it Dock=Fill and add any code that connects the controls. You can layout as freely as you would in a form or a tabpage..
Whenever you want another page of this type, add a new tabpage and add an instance of the UserControl to its Controls collection.
Note: All controls on your UserControl by default are private. This is not really different from placing them on the tabpage directly. But now they are private members of the UC class, so your form and its code can't access them.
Looks like a problem when you're new to it. But if you look at it right, it is a good oportunity to create a leaner & cleaner interface.
Solution 1: Change the control modifiers to public as needed
Solution 2: Add properties to expose those data you really want to expose.
Also note: You can do all layout but can do so only in the UC designer. After adding to a form or tabpage there will be no embedded designer..

I do not want to redirect to other form onclick but display components within the same form in C#

I am doing my college project onclick event I do not want to open a new form but show the component in the same form by disabling the components of the previous option.
For instance, if I click on ADD button, it will open a new form with details to be added to save.
But, I want to show all those components of ADD form in the same form where click event occurs.
My design is something like, all options will be in left hand side and the result / form with component has to be displayed in the right hand side without opening a new form.
Use Panels.
The Panel Control is a container control to host a group of similar child controls. One of the major uses I have found for a Panel Control is when you need to show and hide a group of controls. Instead of show and hide individual controls, you can simply hide and show a single Panel and all child controls.
panel-in-C-Sharp
working-multiple-panels-c-sharp
Use Panel Control
Add multiple panels one over the other, like a stack.
Either use:
panel1.Visible=false ; panel2.Visible=true on button click
panel1.Enabled=false ; panel2.Enabled=true on button click
according to your design
Refer this video: link‎

Looking for controls on parent page from DevExpress ASPXPopUpControl

good sirs!
I've been messing around with the next scenario:
First, I have a webform structured as a WebForm containing a DevExpress ASPXPopUpControl and some other controls. Inside the PopUpControl there is a UserControl (lets call it ucA) containing some other controls and a UserControl (called ucB) that contains a cursed ASPxHtmlEditor (added because it's a new requirement).
When the user hits a button on main webform I show the PopUp (originally was a jQuery dialog but since HTMLEditor messes up with jQuery I've been forced to break the standard and use the popup) which contains the ucA. The user fills some fields in ucA and hit the save button. After user hits, I save some dataz and at this point I need to recover a textbox value placed in the webform.
I'm using Parent.FindControl["myTextBox"] but it considers the popupcontrol as parent. When I was using jQuery (before implementing the editor) it worked like a charm.
I feel it's something trivial but thrust me when I say that this stole many hours of research.
Thanks in advance.
EDIT I forgot to mention that I want to look for another UserControl at main webform. This uc its used to display core messages to the user so when he hits the save button, save happens, popup is closed and i look (Parent.FindControl("myUCMessageBoard")) from the ucA for the usercontrol to display a "Transaction complete" message.
I'm thinking you're going to have to do something a little hacky, by using ViewState. If I understand correctly, you are trying to get access to a TextBox's Text on the Web Form, from a UserControl nested within a PopupControl (so you can't traverse all the way up to Web Form Level).
So, what I'd do at some point in the process is store the text in a ViewState variable that you can access from the User Control. It's not optimal, but since you're already hacking to get it to work, what's a little more hacking?
You should expose all controls from ucA as properties, then look for the control inside the DevxPopup the same way you doing. Given that all the controls that you need at the ucA has properties to access them, you could do all the logic you need!
Example:
public ucA : UserControl
{
public string myTextBoxText
{
get
{
return ((TextBox)Controls.FindControl("myTextBox")).Text;
}
}
/*And lot of controls*/
}
Then you looking for the popup at the Form
var ucA = (UcA)Form.Controls.FindControl("myPopup").Controls.FindControl("myucA");
ucA.myTextBoxText = /*Do stuff here with the text*/
Hopes this help you!

Overlapping Window/Page or Custom messagebox?

I want to preface this by saying I'm a noob with WPF/.net programming.
Here is my question that requires a bit of guidance. I have a window and I load pages in and out as my navigation. On one particular page, when the user clicks on one of the items (button for example), I need to display a small form to gather more information. I'm not sure what the best approach is... what I would love (but do not know where to begin even searching for this solution) would be to open a popup balloon style window with a few textboxes and a submit button.
Other options I've explored would be to use a separate page. Save off the current page and load a new page with these textboxes and a submit button. Or to use a custom messagebox instead (least favorite option).
I would like this new extra info page to blend in with rest of the app so that the main page is still visible in the background. Any suggestions??
You can use WPF's Popup control
<Popup>
<!-- Your Content Here -->
</Popup>
Personally I have issues with WPF's Popup, so have my own custom UserControl that works like a Popup.
I ended up using modal window (ShowDialog) method for this.

Categories

Resources