Multiple interfaces with VB.NET - vb.net

Im building a game with VB.NET
I designed the core of the game in form1 window
But now I need menus. How can I implement this without having 5 or so windows that I show() and hide() ? Doing that slows it down a lot and uses lots of memory. I tried tabs, but I don't want the tabs to appear, just switch. Whats the best way to implement multiple interfaces?
Thanks

You can have one menustrip with all toolstripmenuitems for all five menus.
Make all the toolstripmenuitems invisible (.visible = false) except for those for the "current menu." When you make a toolstripmenuitem invisible, all its subitems also disappear and that menu item is inaccessible.
When you change "menus", you can make another set of toolstripmenuitems visible. You'll only have one menu, but you can make it look like you have 5.

Related

How to prevent auto-selection of radio buttons

When adding an instance of the Gtk# RadioButton class to a GUI, it is automatically checked ("activated") as the first member of its radio button group.
For Gtk, this has been discussed to some extent in another question, with the main point of the selected answer being that users expect one radio button to be selected at all times.
I do not dispute that.
However, I am automatically generating my user interface in a way so each radio button is linked to a data model, but none of the radio buttons can, at any time, get a reference to any of the other RadioButton instances. The data model ensures that one radio button is checked at all times.
Beside being sufficient to match user expectations, I consider this good practice, as like this, data integrity is ensured by the data model, not by the GUI.
Unfortunately, Gtk# will automatically check all radio buttons like this, as it considers each radio button to be the first in its group. For adding the various radio buttons to the same group, I would have to pass the first radio button in the group to the constructor of the other radio buttons - which I cannot, as pointed out above, as I do not have any way to get the reference to that first radio button when instantiating the others.
Setting the Active property of the radio button to false does not help, nor does invoking the Toggle method.
Is there any way to suppress this automatical selection, possibly by subclassing and overriding something I could not find yet? Alternatively, is it somehow possible to force a CheckButton to look like a radio button for this purpose?
If there is really no other solution, I will try and implement the solution suggested in another answer that involves adding a second hidden radio button for each of my radio buttons, but I would find that extremely hacky for production code.
Extension to Josip's solution: Create your own radio button widget, actually containing nothing else than two gtk radio buttons, one of which always is hidden. Your factory then creates this one instead of the original gtk button...
Radio buttons are similar to check buttons except they are grouped so that only one may be selected/depressed at a time.
They require a group to perform their duty properly.
Try the solution from the down, it's not so hacky, just try to add one hidden radio button that is always selected.

VB.NET overlaying panels is not working

I am overlaying a bunch of panels on top of one another. I want to be able to click a button to display which ever panel is in the stack referred to by unique names (panel1, panel2...).
However, the bottom panel some how is always the parent of whoever is on top of it. Therefore, If I were to set the visibility of the bottom panel to false, then nothing on top of the bottom panel can be made visible.
How do I make these overlayed panels independent to each other instead of having a parent-child relationship?
I faced the same situation a time ago. The more pragmatic way that I found was to use a tab control and hide/show tabs accordingly. It is possible to get rid of the label of the tab, so users dont even know about its existence. The rule is to have one and only one tab visible in any given time.

vb.net controls in separate files

Short version: VB.Net Windows forms feature controls that are often dragged from the toolbox onto the form. The code for the control goes right into the form. Usually this is great, but is it possible to write the code for a UI control (like a panel) into a separate file which can then be imported or otherwise included into the main Form Class?
Context (a.k.a. long version): I have a form with an unchanging column of navigation buttons on the left hand side. The rest of the form is taken up by different panels, which in turn have different controls of their own. Clicking the different buttons on the left should cause these different panels to appear (clicking button "A" brings up panel "A"; button "B" brings up panel "B", etc.), but the left-hand menu should stay unchanged.
I'm having a hard time implementing this design in an elegant way in VB.Net. If I make each panel a separate Form, I have to duplicate the code that builds the unchanging left-hand menu in every file, which is terrible. I tried using inherited forms so the separate panels would inherit the left-hand menu from a master form, but that means each click on the menu sprouts the new form in a new window, and although the left-hand menu is inherited, the menu that I clicked and the identical-looking menu in the new window are not the same objects in memory and have no knowledge of each other.
I just want one window with central content that changes based on what you click on the left-hand side. A solution to this would be for the panels to be just that - panels - and not separate forms as I'm currently doing it. But this gets messy organizationally because the code for all of the panels has to be in the one massive master file. Hence the short form of my question (see above): How can I code a panel in a separate file and then bring it into the fold of the main form?
It sounds to me like you want to use usercontrols. Create a usercontrol for each of the four things you want and then add those to a panel, making each one visible or invisible according to which button was pressed.

How do I change the main menu in Cocoa?

I have a cocoa app with two types windows each of which requires a different main menu to be displayed.
In my MainMenu.xib I have the default MainMenu. In Window1.xib I have Window1 and in Window2.xib I have Window2 and it's MainMenu.
When I have the first Window open I have the default Menu, when I open Window2 I get it's menu.
However, when I switch back to Window1 I still see Window2's menu. How do I make the menu that is displayed follow the key window?
Generally, you shouldn't replace the entire main menu every time. It's more compliant with the Human Interface Guidelines to simply disable any menu items that don't apply to the current window. And if you really should have a completely different set of menus in the menu bar, maybe you should split that part of your application into a separate application.
NSApplication has a method, - (void)setMainMenu:(NSMenu *)aMenu. You can pass it a reference to the correct menu in the appropriate window controller, by implementing - (void)windowDidBecomeKey:(NSNotification *)notification.
Keep in mind it may be easier to change just the submenus instead of swapping out the entire main menu, since you won't have to maintain two different copies of the application, help, and other menus that won't change between the two windows.

NSBorderlessWindowMask Window wont show NSPanels if not front most window

I have a window that is set with NSBorderlessWindowMask, and also kCGDesktopWindowLevel. When a NSPanel is supposed to appear from say the selection of a Dock Icon menu or a Status Bar Item menu, the NSPanel will not display if the application is not the front most window.
So this program at this time only has a Status Menu Item (think how QuickSilver is implemented) and when I choose Preferences from my menu it is set to show the Preferences Panel by using Makekeyandorderfront, however unless you have just launched the application and done nothing else, when you select Preferences nothing happens.
I have found that when I choose my menu item for Sparkle's Check for Updates, that the check for update panel will appear and then my preference panel which I told to open will appear.
So it seems like makekeyandorderfront is not really bringing it to the front, perhaps.
Does anyone know how to fix this?
Should I call something besides makekeyandorderfront, or maybe something in conjunction with it?
Thanks in advance
Panels are designed by default to work this way. They're designed as auxiliary windows for your application and always disappear when the application deactivates. You will probably also run into issues with the panel becoming key... but to cure your disappearing panel issue, send this message to your panel:
[panelObject setHidesOnDeactivate:NO];
You should probably be using actual NSWindow objects here instead of NSPanel objects, but since I don't know much about how your application works, you'll have to look into that yourself. For more information on the difference between panels and windows, please review the documentation here: Window Programming Guide