INTRODUCTION
Using C# or VB.NET. I'm trying to make a form's background transparent; this form will be overlaped to other window, it will be a top-most window, so the transparent form (and its controls) must have the ability that they must not receive focus and they must can be clicked trough, this means if for example I perform a left-click on the transparent background, then the window on background of that (in the Z-order window) is the window that must receive the click instead.
Notes:
For avoiding the focus I'm overriding the CreateParams property as explained here.
For making my form transparent, I'm calling Win32 DwmExtendFrameIntoClientArea function and also using SharpDX library as explained here. But I think this really doesn't matter with the question itself.
PROBLEM
I'll show a demostration of what I mean using images. Here below is a image of a form (with no transparency, just to simplify understanding) overlapped to a window of a text editor program; note that my form doesn't receive focus. Well, the problem is when I do click on the form's background (or one of its controls) the window on background (the text editor window) still have focus but it can't receive the click.
Here is the same image of above but with a transparent form:
RESEARCH
I'm not really sure about what to investigate, so I'm going blind trying to find something useful in a trial-and-error stage by overriding the Window procedure (WndProc) of the transparent form to test related windows messages, like WM_NCHITEST or WM_MOUSEACTIVATE message as said here:
Windows form with a transparent background that cannot be clicked through
Make a form not focusable in C#
How do I create an "unfocusable" form in C#?
You can do this by sending click (mouse up & mouse down) messages to the window underneath the transparent window using WinAPI.
PostMessageA
You'll need to find the window underneath the point you require.
WindowFromPoint
You'll have to translate the position of the click events accordingly since messages are processed based on relative window position, not absolute screen position.
I actually did this quite successfully to automatically play a facebook game many years ago.
Check the RAD designer in Visual Studio.
Is the label docked to fill?
Where is the main form clickable?
The transparent color is click-though in the main parent, however, components will still retain clicks.
Related
I'm working in C#, in Visual Studio, and I'm trying to make a transparent form - entirely transparent, though not click-through - without making the title bar transparent, so that there's still something to move the (invisible) window around and (most importantly) close it.
It'd also be nice if the window had visible borders, but that may be a separate question.
If I understand your question correctly, you can Use TrancparencyKey
Set TrancparencyKey and BackColor properties both to same color like Color.Red.
Here is the screenshot of transparent form over visual studio:
Note:
When you use for example Color.Red every thing works fine and you can handle mouse Click. But the behavior is different for different colors, for example Color.Magenta the form can not capture the mouse Click.
This question already has answers here:
How to hide only the Close (x) button?
(5 answers)
Closed 9 years ago.
I got answer for disabling the x button in windows forms but is it possible for completly make hide/invisible the close(X) button and move the maximum button to close(x) btn position and minimum button to maximum button position in a form. without creating custom/user control/new forms
I don't believe you can hide it without hiding/removing the entire control box. The best solution would be to disable it if you don't want a using pressing the (x) button.
#Andy is correct, it's not possible. Those buttons are located in what's called the Non-Client area of the window—meaning that part of the window is (more or less) controlled by Windows and not the program "hosted" in the Window. Note that disabling the Close button also disables the Window's system menu (or Control box menu).
What you may want to do is hide all the title bar buttons and create new buttons on your application form that minimize and maximize the application.
However, I would ask why you feel the need to move the buttons? If you must move the buttons or have a different design for them, I know applications like Trend Micro anti-virus "skin" the window by providing an image for the application window and create custom (a/k/a owner-) drawn controls. They also "skin" the Non-Client area, effectively designing how/where they want the title bar text displayed, the minimize/maximize buttons, etc. But that's a lot of work and generally doesn't look as polished (in my opinion). Plus, people are just plain used to the standard Windows form, which is why it's "standard".
One more thing to think about is using WPF. You can basically redefine the Window template, thereby changing the look and feel (and position) of, generally, non-client area buttons such as the Minimize and Maximize buttons.
You have to ownerdraw the thing,
Hide all status bar setting FormBorderStyle to none
Place a Panel At the top of the form using Dock Top
Create the buttons you need (Minimize, maximize)
Make the Panel Title bar that grags the form Make a borderless form movable
Hello,
Above is the program I am writing. On the right panel is basically two custom controls (the blue rectangle area) I created and just added them as controls to the background panel control when this winform program loads.
I used MS paint to draw out the pop up balloon that I want to see when my mouse enter this control's area. I want to do the following:
1. If mouse enter the control area, the yellow area balloon pop up and populate with the information of that specific control
2. If mouse move out of the control area, the pop up balloon disappear.
Can this be done with Winform application? I looked around and found out about Tooltip class but so far from researching I don't know if it does what I want to do.
I could be wrong but googling around gave me the impress that Tooltip offers very little in term of style. Ideally I want to make this pop up balloon into almost like a border-less pop up window where I can put image , font ect.....at will. Also Tooltip works if you hover over a button or specific field whereas I want the entire control area.
Can this be done? I appreciate if you can point me to any work around if there is one.
I wrote a comment, but I figure I'll expand it into a full answer. This is assuming you want a new control, which isn't a tooltip, for maximum customizability. I did something similar to this for work recently, to act as a non-modal info popup that disappears when clicked.
Creating a Custom Popup Form
What you want is essentially a floating popup that appears over your form, which means you'll want to define a new Form object, rather than a UserControl, as it won't actually be embedded within your other form.
Give it a multiline, non-editable textbox that you can fill with the information you want to populate, then simply call a new instance of the form on your Mouse_Enter event. Close it upon Mouse_Leave.
Adjusting The Style
You'll have to play with it a bit to get it to actually act like a popup and not just a window. I'd recommend setting it to a non-modal popup, and removing the border. You can write a function to automatically size it to its contents. I don't imagine you'll want the user manually resizing it.
Some other things to look into would be overriding the CreateParams property that comes with the basic Form object. You can force DropShadows and TopMost forms without making the form modal. Overriding ShowWithoutActivation to always return true will prevent the form from stealing focus when it pops up.
I'm not sure if you can pull off rounded edges like you have in your mockup. Perhaps you can pull it off with some wizardry in the OnPaint() function, but I couldn't tell you how to do it.
It might be a bit of a pain for fiddling around with, but you can get some good functionality and appearance out of it. If you think you can pull it off acceptably with the ToolTip class, go for it. It took me about a week to get my notifications where I wanted them (though I added several features that you probably don't need to worry about).
Examples
Some keywords to look up in related searches would be Toast Notification and Non-Modal Popup. This might be some use:
http://www.codeproject.com/Articles/442983/Android-Style-Toast-Notification-for-NET
Since you already have implemented custom user controls you might want to try it again. Make a control that is that style and color, changes it's size based on it's text. You can feed it information (such as the text to display) from your existing user control object. You can also have the mouse enter/leave code reside in your first user control.
If you're not sure how to make a rectangle with round corners you can either make it on the fly using a graphics object (which will turn into a bitmap on the screen) or make it how you want it to look in GIMP (or photoshop if you have it) then use that image as the background on your user control. Make the default background transparent (so your voids above the round corners are not grey). If you make a pre loaded image you'll need to be aware you will only be able to scale it equally in Y and X directions. unequal scaling will make it look distorted.
Can you use the Mouse_Enter event on the control?
I want to display a very small image on the top left corner of the windows desktop, it will be a picture of a small note and when you mouse over it, the window will show.
How can I do this in C#?
There should be no borders or regular window graphics
The image will be partially transparent
When a mouse over event occurs a window will display
The image will always overlay other windows
Thanks
I'll try to point you to the right direction for each of those requirements, you can do more research on how to exactly achieve each one using google or stackoverflow.com
You need to create a widows form, and add the image as the background of the form, or add an image control to the form.
after you have that, you can use the following to get your desired effects.
No Border
Set form's FormBoarderStyle propery to None
Transparency
Set Opacity property of the Form to something less than 100%
Mouse over
Use MouseHover or MouseEnter events of the form
Overlay other windows
Set TopMost property of the form to true.
How do I draw a toolbar on the titlebar of a C# winforms window in windows vista? I have a window where it works, except when the window is unminimized/unmaximized it increases in size by about 16x32px. If possible, please provide code examples.
The only way to effectively do it is to handle the WM_NCPAINT message when you override the WndProc method for the Form.
Passing to the base implementation of WndProc will cause the windows frame to be painted, but at that point, you would be responsibile for painting your toolbar elements on the title bar.
You will also want to handle all the other WM_NC* messages as well, which will allow you to process button clicks and the like (which you will need to handle events for your painted controls).
I've been looking around for the same problem, because I wanted to code a ribbon bar with that big button in the upper left corner... The only good source I found was at CodeProject on this blog and this one and another one.