VS Windows Form App, Controlling Hover State (not Blue) - c#

some of my button states in my Windows Form Application are defaulting to a blue Hover state. I am pretty new to VS and I am mainly using the GUI to modify the design, but I don't see anywhere where I can control just the color of the hover state of the buttons.
Can anybody tell me where I control this, whether it be programatically or in the GUI?

The windows operating system handles that.
To modify it, you would have to change the FlatStyle appearance to Flat and then modify the FlatAppearance attributes, which includes the MouseOverBackColor property.
Unfortunately, you lose the visual styles then.

Related

Can't see a button in designer

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?

C# Winform: Remove the border from a standard button?

Is it possible to remove the border of a standard C# Button ? I know that I could set the FlatStyle property to Flat and customize the FlatAppearance property to hide the border but I would prefer to use the Standard property to ensure that the control appears under all operating systems like a default Button. Did you have any suggestions how I can solve this issue? I am working with a Windows Forms Application.
You could use an image and make it clickable, that is one way to avoid the borders, but there are several options. Good luck!
If you are using windows forms and trying to implement Flat UI, Material UI, Metro-Looking controls, you're in hell. It is has limited properties for customizations unless you know how to work with Graphics and Animation. You'll have to use imagebox or picture box and dynamically change its image on different events.
I'll suggest WPF or Windows Presentation Foundation for a more customizable User Interface.

dynamically changing a non-rectangular window in c#?

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.

Control positions in Runtime not consistent with designer

Let me explain put it in just a few simplest lines.
I made a new C#/WPF application project in VS 2013 ultimate (x64).
On MainWindow I insert (for example) a button at bottom-right, actually anywhere..
See image below, but the position of the buttons at runtime does not match what it looks like when I am designing
As you can see from the marked up spots in the 2 images, the controls are mispositioned.
I tried to change some XAML attributes, setting min/max sizes, and so on and on. I am running a fresh-install Windows 7 Ultimate (x64) OS, with "Windows 7" aero theme.
I played around MainWindow/Grid properties (tried almost every one), also when I loaded up some custom theme (for example: Expression Dark) issue persists.
Don't get excited so much. Have some control on your temper.
It seems that you have not set the Right Margin of the button you have circled Red in the above image. Try to set the appropriate margins from the Property Window of the corresponding button and see what happens!

Changing default font in Windows messes up my Win Forms buttons

We have a collection of C# (.NET 2.0) applications that have custom dialog windows. When the user changes the default font size and resolution etc in Windows the edges of the form lose controls (they get pushed off the visible portion of the form) typically dropping off buttons from the bottom. This is problematic for us and will cause issues across other applications using the standard look-and-feel framework we are creating around these applications.
How would you make your entire application independent from windows font changes? How would you integrate this into multiple solutions?
Or better still how can one adapt the entire application to be able to adjust itself with the Windows appearance changes?
WinForms have the AutoScaleMode property, which can be set to either Font, DPI, Inherit, or None. The default is "Font" which, in my experience, doesn't always scale things right. You might try one of the other options (maybe "None" if you don't want your form to scale at all?)
As for making the entire application able to adjust itself, look into the "Inherit" option (you still need to set something other than "Inherit" on the parent or startup form of your application, though).
You could handle the SystemEvents.UserPreferenceChanged event in the Microsoft.Win32 namespace. The UserPreferenceChangedEventArgs parameter will have a Category of UserPreferenceCategory.Window when the system font changes. I think you'll then have to trigger a manual window layout and redraw in response to this event.

Categories