I am working on an application using WPF and visual c#, and I am trying to implement an annotation feature which allows for drawing on the desktop.
My current way of accomplishing this is by making a total screen-sized window with a transparent background, and putting this over the desktop, allowing me to "write" on this invisible window.
However, I have another set of windows that constitute a floating menu of sorts on the screen, and I want this menu to always be interactable, even when the user is annotating (for example, this is where I want to put some annotation options).
When I show my transparent window, however, my menu windows are all behind it, which means i draw over these windows instead of clicking on them. I have tried things like setting topmost on the menu windows, but this does not put them over the transparency.
My current idea now is to make a non-rectangular window out of the transparent window and basically just cut out the region the floating menu is in, and dynamically update this if the user drags the menu to another place on the screen. Is this feasible/possible, and how can I dynamically make these window changes? if this is not possible, is there a better way of forcing all my menu windows to always be on top of the annotation transparency?
edit: as an additional note, is there any way at all to set a z-index of sorts on these windows? that would resolve this, I think, if I could z-index the menu windows all the way to the front and then index the transparency to one behind that, but I was unable to find a way to do this.
edit: someone commented and suggested I re-set topmost = true for my menu windows once I create my transparent window, but this ended up having no effect
FINAL EDIT: I fixed the issue using David Edey's suggestion of setting topmost; turns out I had a rogue line of code setting the transparency as topmost=true, causing this issue when setting the window topmost properties, but now it works like a charm. Thank you so much for your help!
I have built a replica version myself, and setting:
Application.Current.MainWindow.Topmost = false;
Application.Current.MainWindow.Topmost = true;
Brings that window to the front without fail (note that you do indeed need the false call first to actually refresh it sometimes... Not entirely sure why this happens, but it works!) :)
(Obviously replace the call to Application.Current.MainWindow with a reference to your Menu window).
...another set of windows that constitute a floating menu of sorts on
the screen, and I want this menu to always be interactable,
My recommendation is to place the Menu window controls in question into a single control with dependency properties which expose the business logic of the menu. Make sure the aforementioned properties are two-way bound to INotify properties on a viewmodel which ultimately will be accessed/shared with the annotation window.
When the annotation window comes up, it also creates its own menu window control which has the same zorder as the annotation window. The old original menu is hidden(?) or the new one comes up in its location(?).
By design the new menu window properties are also two-way bound to the shared VM. Hence allowing for changes from the annotation menu to go back to the original window via the shared properties.
This slight of hand with a new control, behaves to the user like the other menu control and also changes the data dynamically, for both annotation and the original. Also the second menu doesn't have the problematic z-order issues which you are running into.
Related
I'm on Windows 10, maintaining a C# Desktop application using Visual Studio 2019, putting controls onto a Form (System.Windows.Forms.Form). I'm attempting to change an application; reworking where the controls go etc., so there is code and control design that I want to keep and put into different locations. I am using the visual designer and connecting to code using the control events (as opposed to creating the forms dynamically).
I have Document Outline visible on the left; I cut several groups of controls I intend to paste back later, so all that one particular TableLayoutPanel has in it now is two buttons. But I cannot find those buttons in the designer. I can see them in the Document Outline; they're in a TableLayoutPanel (in a group box in another TableLayoutPanel on a TabPage, etc.). When I click on a control in the Document Outline, the corresponding control is usually highlighted in the View; however, when I click on either of these buttons, nothing is highlighted in the view.
I tried resizing the Form (which determines the sizes of all these panels/tableLayoutPanels set to 'fill'); it's currently at 1367,850; one of the button locations shows as 664,752, but I don't know in what coordinate system that applies. I tried manually setting the location to 50,50 in the properties window, but it won't let me change that there.
These buttons appear at the bottom of the form; they've never appeared there, but I've noticed sometimes the designer has shown dotted-line outlines of them outside the form entirely. They appear in place when the application is run.
I've tried changing between the 100% scaling and the 125% scaling; that didn't help. For two buttons, I suppose I could delete them and recreate them, but there are many, many controls on this UI, and if there's some trick to making things appear I'd like to know about it.
Is there a trick to this that I'm missing?
When I create a new window using .Show(), it shows the new window, however my icons are grouped like below:
I don't want that. I want the icons to be separate because I want my users to easily open the window that they want instead of having to click it, view the list of open windows, then choosing which one they want every time. I don't want to use .ShowDialog() because I need the users to be able to focus on either window no matter the state of the other. Meaning, both windows will need to be open and the user will need to be able to interact with each of those windows regardless of if the other window is open or minimized.
I've tried setting the parent, but I don't think I'm taking the right approach. I've never worked with icons before, so excuse my lack of knowledge.
var w = new Window();
w.Owner = Window.GetWindow(this);
w.Show();
I will be changing the icon of the second window that gets opened so that the user knows which one to click on based on what they want. I'm just trying to get around the grouping that seems to be the default.
(If i'm correct) In Windows it's possible to assign a seperate AppUserModelID to your shortcut icon to prevent the default grouping of icons, this is the page explaining how to define and assign a seperate AppUserModelID. I would suggest reading the provided source thouroughly.
So I have an odd issue while trying to use a WPF TextBox with SpellCheck enabled inside a Winforms form, using the custom control defined in this post.
This works just fine, I've tried using it in my own sandbox project and it looks great. The problem is when I try to replace the Winforms TextBoxes inside one of our existing forms. The SpellCheck context menu is "trapped" inside the control, so all I can see are the up/down arrows of the menu.
I'm not too familiar with Winforms, as I mostly work with WPF, so I'm having a hard time determining the problem. The text box shown above is the custom control as mentioned in the linked post. The control is contained in a forms TableLayoutPanel. How can I get the context menu to expand and actually be visible?
Edit
First, to clarify, the context menu appears normally when displayed in a console application that opens the form. I did a little more testing and created a new web project (what the original problem project is) with a button that opens the form, and then the problem behavior occurs. What difference between the console application and the web application would cause this?
Edit 2
I tried the suggestions in this post, thinking maybe the context menu really was just being automatically sized incorrectly (to fit the parent control). But none of those solutions seemed to make any difference either.
Edit 3
After using snoop to look at the differences between the working context menu (windows application) and the not-working one (xbap) the only difference I could see was that the DesiredSize of the xbap instance's context menu has a smaller size, I just have no idea why.
The wpf control is a control which is hosted in winforms via the ElementHost.
Hence it lives within the area provided by the parent.
The only way is to expand it, is to change the size of the parent. Give it a try by creating a winform supersized textbox as a quick debug example. Note whether the size change works on not. If it does can the GUI accommodate that change? I can't answer that.
I have an small appliction window , pops up when a tray icon clicks. Inside that i have provided context menu (windows form context menu), the problem is, whenever i rightclicks on form, the context menu is appearing but on disappearing of context menu, border of context menu still exists. As i minimises/closes and reopen every thing works fine again.
Any one has any idea why it is behaving like so?
Ravi Naik.
Set DoubleBuffering to true on the form. This should sort the problem out.
Unless you are drawing the stuff yourself using a Graphics object? Are you?
If you are then look up Double Buffering, you can find out about this at a few places, such as Bob Powell and Code Project.
If it doesn't and you want a quick hack to get around it, on the context menu collapse event you could call form.Refresh() but avoid this at all costs.
I am trying to create a panel which will have a set of "buttons" on it.
These buttons should have the following behaviour:
Appear similar to a tag (with
rounded edges)
Contain a red
cross to remove the filter/tag from
the panel, similar to the way internet
explorer tabs have an embedded cross to close the individual tab.
allow the user to click
on the tag and respond like a normal
button (as long as the click is not
in the red cross)
Number 1 is no problem, this is just appearance, however, regarding numbers 2 and 3, I am not sure if there is already code out there do to something similar...and I dont really want to reinvent the wheel if I can avoid it!
My question is: Does anyone know if there is something out there in infragistics which will do this simply, or will I need to write this myself by subclassing winform buttons?
Thanks in advance!
Is this new development or maintenance of an existing project?
If it is maintenance, you have a somewhat tougher time ahead. You'll implement a UserControl, probably segmented into two buttons. Use docking to get the behavior as correct as possible. The far right button would contain your cross image; the left (which would need to auto-expand as you resize the control) would contain your primary button behavior. Play with the visual styles until you get them right (EG, removing borders, etc).
If this is new development, and you haven't gotten too far into it, you might consider using Windows Presentation Framework (WPF) instead of WinForms. It will be easier to build the control and get it to look exactly how you want it. WPF includes an extremely powerful control compositing system which allows you to layer multiple controls on top of each other and have them work exactly as you'd expect, and it carries the added advantage of allowing full visual control out-of-the-box.
Either way, this is more work than dropping in an external component ... I've used Infragistics for years, and I can't think of anything they have which is comparable. The closest, but only if you're building an MDI application and these controls are for window navigation, is the Tabbed MDI window management tools -- and there, only the tabs (which replace window title bars) have this behavior.
I don't think that infragistics can do something like this. The UltraButton control can't.
Implementing a own control wouldn't be that hard.
your probably going to have to make a costume control for this type of work.