Windows Forms popup wtih context menu behaviour - c#

I want to create a popup in Window Forms which behaves like a context menu.
I need to display additional fields on click. These fields should be displayed inside an popup/overlay (either implemented as a separate form or a UserControl, I'm ok with both). That overlay should appear on click and disappear on every action that would make a context menu disappear.
What is the easiest way to do that? I have several nested control on the form and I would like to avoid attaching events to every one of them... (besides im not even sure which events to listen to)

Related

App has too many tabs opened in the task-bar

I'm making a WinForm app in C# (Visual studio) for fun. I came across a low-priority problem. It doesn't affect how the app works. But...
On the starting page, I have a button to open a Form1, inside Form1, there's a button to open a Form2 and so on.
At runtime, when I open a form, its parent form does not close and every form is a separate tab in the task-bar. As the layers grow, I'll have more-than-acceptable amount of tabs down there...
Is there a way to have only 1 tab?
I've tried:
Adding a parentForm.close() line when opening the form, but that was bad.
Instead of creating another form, putting everything in a panel, and bringing out another panel using code, but if there are too many layers, the code gets ridiculously long.
There has to be a simpler way right? Please shed some light.
Yes, you have a property in every form called ShowInTaskbar which is true by default. You can change that in the form properties under Window Style section or changing it by code manually:
Form2.ShowInTaskbar = false;
Form2.ShowDialog();
Configure to false all forms but the first one in order to achieve your desired behaviour.
Make sure your opened forms are dialogs or you are put them on top so user can never get in the situation where the form is behind and they cannot close it.
Anyway, with a proper form parenting configuration (if it fits your needs) you won't need this, as children forms won't appear in the taskbar.
If a form is parented within another form, the parented form is not displayed in the Windows taskbar.
Make sure you check the MSDN Documentation about this.

Enable events in main windows while modal window is active

In a WPF window I implemented a component that gives an indication of all active errors in the system.
The component is located in the task bar and
If one hovers over the component a tool-tip is shown with summary info
If one clicks on the control, a panel is the activated that is showing a detailed list.
In the application we also use wizards implemented as modal windows.
Now, here's my problem: if a new event occurs in the system during an active wizard, the component in the task bar is updated however I cannot use the hover event to see a summary. Both events (hover and click) are not usable due to the modal dialog that hides the parents message loop.
Is their a way (or what's the best solution/suggestion) to have at least the hover message active while the modal wizard is present.
Thanks.
They don't call it "modal" for nothin' :-)
Humor aside, depending on your exact scenario, here's two options and a third option that's a bit more involved and you probably don't need it but it can handle a wider range of scenarios:
Option 1. It sounds like you have a normal app that does not show its MainWindow and is using only its taskbar presence. If this is the case then you don't need a dialog at all, simply use the MainWindow itself as the "dialog".
Option 2. If you are already using the MainWindow visibly then use a pseudo-modal approach whereby you don't actually use a dialog but all other controls except the control acting as your "dialog" control are hidden/collapsed.
Option 3. Use two separate processes. Basically, this is two separate apps - one is your taskbar component and the other is your main app. Use IPC to link the two - e.g. I have used a Windows pipe for such a thing and it works fine.

Navigate on several WinForms in a C# app

I'm building a C# form application which contains several forms. (Login, Menu, Products, Users, Settings..etc).
This is the structure how the navigation happens.
Currently what I'm doing is hide the current form and create a new object of the next form and display it.
this.Hide();
Menu obj = new Menu();
obj.Show();
If I create objects for each visit to a form, there'll be lot of objects of that form. Right ?
Is this the correct way of doing it ?
And some of the navigation are bidirectional. There's a button on each form to go back.
So, what's the efficient way of closing the current form and go to next.
I think a better (this is subjective) flow would be:
Login and Menu are Forms that are considered top level.
When Login is complete, it is closed (not hidden), and Menu appears as the only form.
From Menu, you can pop-up Modal dialogs for the other screens. But only one of them can be open at a time. When they're closed, the user can control the Menu form again and open another screen.
Note, by Modal dialogs, they would appear on top of the Menu form, but Menu wouldn't be hidden. It is simply waiting for the modal to be closed before it regains control.
The problem with windows that appear and disappear (regardless of whether they are closed or hidden) is that the end result may be disconcerting to the user. They may feel that the program has quit and the link between prior and consecutive windows may not be easily understood.
UserControls
Alternatively you may want to consider replacing your other windows with UserControls. This way you have a main window that consistantly stays open and you simply embed a UserControl representing the other pages into it. Thus making it more obvious to the user that there is a notion of an consistent "app".
Users; Products and Settings, instead of deriving from Form would instead derive from UserControl. To move from say Users to Products, simply remove Users from the Controls property; create a Products control and add it to Controls ensuring that it is set to Dock.Fill.
I see no reason why Login still can't remain a modal dialog though.

design panel without parent form in Visual Studio

Anyone come up with a way that I can design a panel without a form?
On the surface usercontrol doesn't seem the way to go.
Background:
I come from a text editor world and VS is new to me. We did everything with panels instead of forms. So open for learning. Specifically have a base class panel (ExtendedPanel) that defines some basic controls: Cancel, Save, Save and Close. This ExtendedPanel then will be used for ClientExtendedPanel that is tied to a bindingsouce clientBindingSource. This is all tied to my entity framework model. So I will add, edit and delete sql datarows for my Client table. If no changes have happened by Save button will not be enabled. If I make a change but hit cancel it will warn me. I've done all this before but since I left that company I don't have access to the code base and they didn't use VS (text editor only)so it wasn't really transportable anyway.
All that background so I can ask: Is usercontrol the way to go, or is there something that will allow me to visually add controls to a panel like it is a form?
Yes, a UserControl provides a form-like canvas in the designer for you to add other controls (buttons, etc).
You can do this too by inheriting a panel and writing the code to add the buttons and wire their events, etc, but you won't get the designer support.

"iframes" within Windows Forms' form

I want to prepare single window with static parts and variable content just like iframes at HTML (with menu and the page itself). How to do so via the Windows Forms Designer? I could use tabs and maybe somehow disable the possibility to manually switch between them... but I guess there is some more elegant way to do so, right?
Create an user control and place it on the form. User control will be your 'iframe' and the rest of the form will be 'static' contents.

Categories