C
C#2y ago
Diogo

❔ Prevent clicks through Transparent Background Form

i made a transparent background form (BackColor: Gray and TransparentKey: Gray) but i would like to prevent clicks through it. i found some stuff online but i'm not sure how to implement them since i'm a begginner, can you guys help me with that?
17 Replies
JakenVeina
JakenVeina2y ago
context, please
Diogo
DiogoOP2y ago
sure, i made a color EyeDropper tool for my application, i use a mouse hook to get the position in the screen, it starts when the user clicks in a button in the main form, and when a mouse click happens it gets the position you clicked, gets the color of this position and stops the hook But there's a problem, if i need to get another app button color i would have to click in this button, so i had the idea to make a transparent window that follows the mouse, you would click on this window instead of clicking in the actual thing, i would show it when the user clicks in the button to pick a color and hide it when a click happens, and i could use this same window to show the color you're hovered at (if you think there's a better solution for this please let me know) But when you create a transparent window you can click on stuff thought it (example in the image below), i wanted to prevent this.
Diogo
DiogoOP2y ago
something like this
Diogo
DiogoOP2y ago
here's a better explanation
JakenVeina
JakenVeina2y ago
okay, but like... still no context what framework is this?
Diogo
DiogoOP2y ago
oh, my bad, its .NET
JakenVeina
JakenVeina2y ago
alright what framework?
Diogo
DiogoOP2y ago
the GUI framework is Windows Forms
JakenVeina
JakenVeina2y ago
lovely so, you're attempting to make an EyeDropper that works for the ENTIRE screen, not just your app?
Diogo
DiogoOP2y ago
yeah, actually, i already have the base working
JakenVeina
JakenVeina2y ago
it sounds like you're well on the right track already that's roughly what the Windows Snipping Tool does, for example it tosses an overlay over top of what you're trying to screenshot so, I don't know what the semantics are for this in WinForms, but in WPF, transparency is handled to allow for exactly what you describe when you're drawing a control or something, you assign a Brush to it if you assign a Brush with a color of #000000FF I.E. fully transparent, it will "paint" transparent pixels on that control so, the control is there and intercepts all the mouse input and such, but it's still transparent however, if you assign the Brush to be null, then it doesn't paint anything and a control that doesn't have any painted pixels won't receive input you want whatever the equivalent mechanism is in WinForms, if any
Diogo
DiogoOP2y ago
ooh ok i think i saw something like that, you override the paint of a control, right?
JakenVeina
JakenVeina2y ago
you of course could also just set your window to be...not transparent make it #000000FE or more like Snipping Tool #00000077
Mayor McCheese
You can't blow the chrome away in windows forms iirc So if you're fine with still seeing the border Though that may have changed idk
JakenVeina
JakenVeina2y ago
I mean, "don't use WinForms" is definitely the real answer at least part of it
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server