c#


Making a transparent/Click-throughable VB.net form clickable with a toggle


So I was working on a transparent add-on VB.net program that will be clickable only if you click shift. E.g. It will just stay there but clicks will go through it unless I hold shift f.e
I saw this and tested the codes,
VB.net Click through form
However I tried to change some controls but none are able to give me a kind of "toggle". Any clue of what I can fix for it?
Answers in C# are welcome as well as I can program C# instead if it is not do-able in VB
Edit: Code I have been trying to use is this
Imports System.Runtime.InteropServices
Public Class Form1
Private InitialStyle As Integer
Dim PercentVisible As Decimal
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitialStyle = GetWindowLong(Me.Handle, -20)
PercentVisible = 0.8
SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)
SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)
Me.BackColor = Color.Red
Me.TopMost = True
End Sub
<DllImport("user32.dll", EntryPoint:="GetWindowLong")> Public Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<DllImport("user32.dll", EntryPoint:="SetWindowLong")> Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
<DllImport("user32.dll", EntryPoint:="SetLayeredWindowAttributes")> Public Shared Function SetLayeredWindowAttributes(ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal alpha As Byte, ByVal dwFlags As Integer) As Boolean
End Function
End Class

I found the color to make all the difference; afaik this is a legacy bug/feature we can make use of.
Here is a minimal example:
public Form1()
{
InitializeComponent();
BackColor = Color.FromArgb(123,234,34);
TransparencyKey = BackColor;
Text = "Click Me!";
KeyPreview = true;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Shift)
{
BackColor = Color.Fuchsia;
TransparencyKey = BackColor;
Text = "Click Through!";
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
BackColor = Color.FromArgb(123,234,34);
TransparencyKey = BackColor;
Text = "Click Me!";
}


Related Links

What does the * mean in “res://*/”?
Is there a unit-testable way to upload files to ASP.NET WebAPI?
parsing CDATA in XElement
How can I monitor entire computer for any file change?
merge SQL tables into common datagridview
SlimDX load precompiled shader
C# GetMethod doesn't return a parent method
asp.net MVC 4 External Login Provider - 'No OpenID endpoint found' (google)
Can't add Office Interop Refs (Powerpoint specifically) to C# project
How to retrieve specific text from a string in C#?
Calling a public method in Windows Forms
c# Xpath with multiple namespaces
How to get a e.CommandArgument from a row in a gridview while using a dropdownlist inside it in asp.net c#?
Build Where Clause (not sure PredicateBuilder will work for me)
How to store coroutines inside a List?
Issues with WebConfig file while deploying ASP.NET website

Categories

HOME
logging
system-calls
cors
cxf
packet
xamarin.forms
app-store
thermal-printer
ms-access-2010
browser-cache
aggregation-framework
logstash-configuration
react-select
template10
google-street-view
aiml
turn.js
ajaxcontroltoolkit
formulas
screen-scraping
ps
priority-queue
orgchart
sqldependency
drawrect
wordpress-rest-api
visual-studio-debugging
flickr
webmock
border-layout
leaderboard
extern
mongoid5
scalamock
ngrok
lfe
observer-pattern
socketcluster
vertical-alignment
nshttpurlresponse
anonymous-function
serverless-architecture
flask-socketio
riemann
dotnet-cli
dynamic-linking
photoshop-script
node-java
jenkins-docker
richtext
cc
petapoco
codesniffer
huawei
csc
jmap
methodology
dynamics-nav-2013
uinavigationitem
sicstus-prolog
mri
iphone-6
dojox.grid
conditional-comments
windows-search
episerver-7
hotlinking
traceur
xps
maven-javadoc-plugin
xml-validation
thucydides
google-mirror-api
friendly-id
myrrix
grape-api
record-locking
panelgrid
latex-suite
zepto
rfc822
correctness
m3u
jquery-1.8
php-gettext
github-archive
reflexil
yii-cactiverecord
clgeocoder
httppostedfilebase
gmagick
lwp
cryptolicensing
xcdatamodel
chars
system-analysis
disk-based
httpbrowsercapabilities
ironpython-studio





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm