Translucent windows form - c#

The look I'm going for is like
where the sidebar is semi-transparent and the background can be seen through. However TransparencyKey only takes into account the pixels at the top, if there is another panel on top that means that together they do not fit the transparency key then it will be opaque.
I have the TransparencyKey set to Fuchsia and the grapefruit sidebar is on top and is changed to sidebar.BackColor = Color.FromArgb(128,255,255,255); on load.
As you see the TransparencyKey only works on the top.
I have also tried setting the transparency on the form with undesired results.
How would I go about making the sidebar translucent?
Solution v

You just can't do that in winforms. Period. It's an antiquated technology that doesn't support "real" transparency. Whenever you see the word "transparent", it really means your control will inherit the back color of its parent. It does not mean you can see things that are behind it.
You may be able to do it with WPF, though I'm not entirely sure.

As noted by #JeremyThompson WPF is absolutely fine at doing this.
Inside the window include WindowStyle="None" AllowsTransparency="True" Background="Transparent" and then use panels/canvases as normal.

Related

Clickable Screen overlay in C#

I am looking for some technologies or ways to create an application which should work like an active (clickable) overlay.
Let's say that we have running application which is always on top. My idea is to create a section on the left or right side of the screen. I'll try to explain in the fast sketch below:
As seen from the image, not only I want to create overlay which is on top aswel, but I want to adjust screen size for "App running always on top"
Is something like that possible?
If so can you please navigate me to the right direction?
PS: My app should have some clickable elements like radio buttons etc.
Thanks a lot
I think you want something like the window that appears when you right click an icon on the Windows taskbar. This is just a Windows Form without titlebar (here you can read how to hide titlebar: https://stackoverflow.com/a/7483026/14940782).
Then, you can add Opacity or BackColor to the form to make it semi transparent or with some color you want. BackColor allows Transparent, by the way.

Windows Form Awkwardly "Resizes" when Started

I'm using Windows 10, Visual Studio 2017 and writing a C# Windows Form Application.
I have a windows form application that I am writing (partly in an attempt to get better at writing such things). I have designed my form nicely, with everything spaced and sized properly, but when I press F5 to start the form to debug it, I find that it loads at about 75% the size of the one I see in the designer.
This resizing seems a bit hit and miss, with buttons that were previously aligned no longer being so, and text no longer fitting in its spaces (see pic - the top part shows the designer and the bottom shows the actual form being run).
I would like to have the designer accurately reflect the final look of the form - does anyone know what is going on or how to avoid the problem? Everything I have looked at on the web talks about choosing to resize the form, not this enforced resize!
Have you changed the whole form font size? By default WinForms designer set
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
try changing the AutoScaleMode and see what happens.
I've experienced similar WinForms designer issues when the default Font (in the form property) size is not 8,25pt. I dont't know why but seems related to desktop and/or screen configuration. Not sure but some weird behaviours could be bugs (WinForms is now quite old...).
AutoScaleMode.Font means that form scaling is based on font size. So trying changing different font settings can solve the problem.
hope this help
When designing the form, the form automatically sets the anchor points to Top Left. You will have to set the anchor points to your form.
The anchor style works like this. On a control if you set anchor points to:
Top/Right then the control stays in the Top Right.
Top/Left then the control stays in the Top Left. Bottom/Right then the control stays in bottom right. Bottom/Left then the control stays in bottom left.
Top then it stays at the top.
Bottom then it stays in the bottom.
Left then it stays in the Left.
Right then it stays in the right.
Top/bottom stretches top to bottom.
Left/Right stretches left to right.
Now when you anchor a control to any of those combinations they will stay in that location when form is maximized. Controls can anchor to each other as well.
I hope this helps.
Also here is a tutorial I did on this.:
https://youtu.be/wlZ6pt79v1E
accurately reflect the final look of the form
Your form's appearance is mostly decided by the end user. Font, size, colour, scale, contrast... all these things are under the users control, not yours.
Consider using split panels, and maybe some flow panels. Get used to 'randomly sizing' the form when you think you've finished designing, to see how it reacts to being the 'wrong size'. Someone will find a way to shrink or grow your form, and handling that gracefully is easier than enforcing a view.

Does the size of a Windows Form include its Border?

When you set the size of a windows form, ie;
Form1.Size = new System.Drawing.Size(700, 500);
Does this include the border which windows puts around the form? Because I have added images (via pictureBoxes) which are 700x500 to my form, and they have been cut off by the border.
Also: When I say the border, I mean the default windows border which you can drag the edges of to resize it, as well as contain the red X, Minimize, and Maximize buttons.
That depends, you'll get a different size when you target .NET 4.5 for example. The border is always included but you don't really know how much of the border is included. An issue with the fat borders you get with Aero and the skinny ones you get in XP.
It is almost always the wrong thing to do. You always want to assign the ClientSize property instead. Important, it doesn't include the borders so you can be sure that controls still fit.
And hard-coding the size is always wrong as well. Your form will be rescaled, depending on the video adapter's dots-per-inch setting. The larger the DPI setting, the bigger the form needs to be to still fit its content. So the correct statement ought to resemble this:
this.ClientSize = new Size(PictureBox3.Right, PictureBox3.Bottom);
On the assumption that "PictureBox3" is the control in the far right-bottom corner that you want to keep visible. This statement needs to appear in the Load event handler to ensure that rescaling was done, it can't work in the constructor. One of the very few good reasons to use the Load event.

Any descent WPF Custom Window Theme, no border transparent with resize on simulated borders?

I've been looking around for quite a while now and can't really find a complete example and may just be missing some small element.
I'm trying to create a WPF Theme/Style/ControlTemplate/etc for a WINDOW. The one where Window borders set to none, allow transparency, and background set to transparent. So, yes, this means I have to define the buttons, borders, background, etc as I've found in other samples.
I've found a few links that utilize (and have that working) through the use of a "Thumb" control anchored to the lower-right.
What I'm missing is how to do resize from the respective borders that are constructed within the new ControlTemplate of the theme. I do have the buttons working for things like min/max/restore/close, but can't quite get how to handle the resize.
Thanks
I've used this link once. If I remember well, the resize border could be set to work as an arbitrary amount of pixels from the sides of the Window, even without a "real" border element.
http://www.codeproject.com/Articles/131515/WPF-Custom-Chrome-Library

transparency in windows forms C#

if the transparentkey property is used to make the top level form transparent,it works , but it also makes the main form click-throughable. I want the opposite of this, that the form becomes transparent, but is still able to recieve clicks. can this be done ?
Here is een solution. The form is totaly transparent and still clickable.
There is also
myform.Opacity = .75
.. which you can change as required. It may work better depending on your needs - you don't state whether its the whole form or only part of it you want transparent. Also, from MSDN on TransparencyKey:
Any mouse actions, such as the click
of the mouse, that are performed on
the transparent areas of the form will
be transferred to the windows below
the transparent area.
.. so it would seem that wont help you at all.

Categories

Resources