Skip to content

Instantly share code, notes, and snippets.

@freakboy3742
Created September 29, 2019 17:02
Show Gist options
  • Save freakboy3742/552fa5dec922b7150de91a4321689791 to your computer and use it in GitHub Desktop.
Save freakboy3742/552fa5dec922b7150de91a4321689791 to your computer and use it in GitHub Desktop.
IMessageFilter on Python.net
import clr
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms as WinForms
class MessageFilter(WinForms.IMessageFilter):
__namespace__ = 'System.Windows.Forms'
def PreFilterMessage(self, message):
print('filter', message)
return False
class HelloApp(WinForms.Form):
def __init__(self):
self.textbox = WinForms.TextBox()
self.textbox.Text = "Hello World"
self.Controls.Add(self.textbox)
def main():
form = HelloApp()
app = WinForms.Application
f = MessageFilter()
app.AddMessageFilter(f)
app.Run(form)
if __name__ == '__main__':
main()
@freakboy3742
Copy link
Author

For those that find this GIST - the problem was identified as pythonnet/pythonnet#965

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment