Customizing look of ContextMenuStrip - c#

I created ContextMenuStrip for my tray icon, and i learned how to add new options there, how to add icons, how to mark them as checked, and how to change whole Context Background.
The thing is i dont know 2 things i would love to learn.
1.How to force newly created options to "continue" background of main Context menu, so they would show rest/same photo?
I created these marked items in code, when adding new folders in my program, folders names are added there as a groups.
2.How to change the look of ContextMenu completly. Is it possible in Visual Studio c#? Any tutorials? (i mean that program name on the left side of menu for example)
Example:
Image to example tray menu
EDIT: I use that do add items under "Grupy":
ToolStripItem item = (contextMenuStrip1.Items[2] as ToolStripMenuItem).DropDownItems.Add("" + Path.GetFileName(#"" + folderBrowserDialog1.SelectedPath));
item.Click += new EventHandler(item_Click);

Related

UWP MenuFlyout in Application.Resources - how to assign events?

I'm relatively new to UWP, but I have good WPF background.
What I need is a simple context menu for the application. User "right taps" anywhere, menu opens, user taps an item and things happen.
It looks basic and simple. First I add MenuFlyout element to my Application.Resources. Then, in MainPage I just show it with ShowAt method. Works.
To my greatest surprise when I tried to add events to menu items, VS told me it's invalid, events cannot be added in App.xaml.
So here's my assignment (in App.xaml.cs):
MainContextMenu = (MenuFlyout)Resources["MainContextMenu"];
MainContextMenu.Items.First(i => i.Name == "NavToCalibration").Tapped += NavToCalibration_Tapped;
The problem is - the handler is never called. I run my app, open the menu, click on the item and nothing happens. The assigned method is not called. What am I doing wrong? Why the handler is not called?
The assignment IS executed on application launch.
I'm also surprised I haven't been able to find any example or tutorial on doing such a simple and basic thing.
There is a good reason I use app-wide context menu instead of other controls. The app displays test images, it has to be full-screen (or maximized window) without interfering elements.
Now I will try to move my menu to the page resources, my pages will have different context menus anyway. But I'm really curious what's wrong in MenuFlyout defined in App.xaml?
Whoa. I tried to move my MenuFlyout to MainPage. I was able to assign Tapped event in XAML. And it also is not triggered! Now I'm completely lost. Any ideas?

How to implement Visual Studio style Add or Remove Buttons toolstrip

I want to implement visual studio style Add or Remove Ruttons toolstrip like following
in my winforms application, how can I achieve this?
I haven't tried anything on this as I am not sure how to start and I don't have much working experience on winforms.
Please suggest.
At first glance it doesn't look all that difficult.
Just add a ToolStripDropDownButton to your ToolStrip with no image or text. That will make the appearance seem more or less similar.
Add to this drop down button one ToolStripMenuItem with a "Add or Remove Buttons" caption. We'll call it AddRemoveMenuItem.
Now populate AddRemoveMenuItem's child menu items with menu items representing all your configurable ToolStripItems. You can link menu item and configurable tool strip item through the menu item's Tag property (you could also subclass ToolStripMenuItem adding a ToolStripItem LinkedToolStripItem { get; set; } property but I don't think its really worth it).
All these "linked" menu items will have to handle their Click events where they will switch their linked tool strip item's Visible property and synchronize their Checked state accordingly.
I'd do that the following way:
linkedMenuItem.Click += (sender, e) => linkedMenuItem.Checked = !linkedMenuItem.Checked;
linkedMenuItem.CheckedChanged +=
(sender, e) =>
{
var linkedToolStripItem = linkedMenuItem.Tag as ToolStripItem;
if (linkedToolStripItem != null)
{
linkedToolStripItem.Visible = linkedMenuItem.Checked;
}
};
When starting up your application set the linked menu items Checked state accordingly to your app's default settings, user settings, etc. and you are done.

.Net controls show ghost menu items; double buffering doesn't work

I have a winforms application with a menu. The "New" item on the menu creates a new control which has a lot of sub-controls, so it takes about 300ms to construct the control.
When you click the "New" menu item, you see something like this for a brief moment:
As you can see, the menu disappears over some of the form, but over the toolbar, for example, you can still see it.
I tried this solution How to double buffer .NET controls on a form?, but it caused more problems than it solved (Laggy menus, crashes when window is not maximized).

Create wizard some clarification

I want to create simple wizard with 3 pages
Page 1 have just next button
Page 2 have next and previous
Page 3 have previous and finish
I have created the pages and add to them needed buttons and in the events I have call to the next pages, for instance in page one in the button click I added the following code
private void Button_Click(object sender, RoutedEventArgs e)
{
p2 = new Page2();
NavigationService.Navigate(p2);
}
In the main window cs I have changed the inheritance to NavigationWindow instead of Window and in the xaml also. Currently its working but I have 3 questions.
The pages which displayed is part of the main window, how can i avoid it, since when I run it the buttons place is not like I put in the designer? It was changed.
The button currently in the Grid, should I put them in different control (the button place should be like any wizard in the left buttom of the page) ?
How can I avoid the navigation arrows in the page right upper screen?
Thanks!
To answer your questsions in reverse,
3. How can I avoid the navigation arrows in the page upper right screen?
I have an opensource library http://winchrome.codeplex.com/ that re-styles navigation windows in several ways. For example these are all NavigationWindow s
In short you just style the NavigationWindow to only show the parts you want.
2.The button currently in the Grid, should I put them in different control (the button place should be like any wizard in the left buttom of the page) ?
If you look at the styles from WinChrome then you will see that it is just a case of rebuiliding the UI as you want and providing a ContentPresenter to hold your pages. e.g. the VS2012 style applies lots of styles on the window but avoids adding back and forward buttons., whereas the Win7 style rebuilds the back and forwards in a Win7 Style.
If you do this however you will need a means of passing your enabled or visible states to the buttons outside the pages. Take a look at http://www.codeproject.com/Articles/8197/Designer-centric-Wizard-control for how to do this in Winforms. In WPF you could either derive from your Pages to create WizardPage classes with CanBack, CanNext or IsFinish properties, or alteratively define attached properties to do the same (There are examples of how to do this in VS2012.cs where we define the glow color)
And finally
1. The pages which displayed is part of the main window, how can i avoid it, since when I run it the buttons place is not like I put in the designer? It was changed.
I'd need to see some code to comment on how you've done it, but if you look at any of the demo programs in WinChrome then you can see how I've done it without problems.
Good luck!

Finding the location of a UITabBarItem in Monotouch Xamarin.iOS

Im trying to implement my own popup menu from a UITabBar.
My app allows users to specify which menus are displayed on the tab bar and I'm not keen on the default "More" button that iOS uses when there are a lot of tab bar items so I would like to create some of the tab bar items to be "Sub menus" that pup up a menu of further buttons. I would like it to pop up from the tabbaritem itself and the order of the tabs may not be the same for every user.
So far I can find the tabbaritem the user has selected but next i need to know its location so I can animate a popup menu from that location.
Does anyone know how I could go about finding the frame or position of the selected tabbaritem?
You can iterate trough the subviews of your UITabBar and get only those subviews which are a type of UITabBarButton class. Then you get the frame of the subviews you are interested in.
List<RectangleF> tabBarButtonFrames = new List<RectangleF>();
foreach (var view in this.tabBarController.TabBar.Subviews) {
if (view.ToString().Contains("UITabBarButton")) {
tabBarButtonFrames.Add(view.Frame);
}
Console.WriteLine(view.ToString() + "\t" + view.Frame.ToString());
}
Note: This link contains more ways of getting the Objective-C class names from poupou

Categories

Resources