惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - Pharaoh

jae的mongo数据库管理工具(原创) 面是否包含点的算法 简单的远程控制软件 学习Python,编写了个网站 - Pharaoh - 博客园 将Unicode字符串转换为普通文字 - Pharaoh - 博客园 测试从Mathon插件发表 VS集成环境中的JavaScript脚本语法检查 测试用Windows Live Writer [转]滚动条颜色生成工具。 用资源管理器打开“打开文件”对话框的目录。 - Pharaoh - 博客园 用Word2007发Blog的配置方法(多图)。 - Pharaoh - 博客园 测试Word2007 用批处理写的显示磁盘剩余空间的小程序。 总算亲自看见了一个网站被黑后的页面。 [转]XP如何禁止媒体文件预览 Google Calendar V2.0汉化 快捷方便的对js文件进行语法检查。 C#通过http访问olap 事开机时Num Lock键打开。
用IronPython作为.Net的脚本语言。
Pharaoh · 2006-08-07 · via 博客园 - Pharaoh

周末看了关于IronPython的介绍,觉得用IronPython作为.Net的脚本语言还不错,今天试验了一下。
不可错过的MSDN TV —— IronPython: Python on the .NET Framework (上)

添加IronPython的引用,在按钮事件中调用py脚本。

        private PythonEngine engine;
        
private void button1_Click(object sender, EventArgs e)
        {
            
if (engine == null)
            {
                engine 
= new PythonEngine();
                engine.Globals[
"win"= this;
                System.IO.FileStream fs 
= new System.IO.FileStream("scripting-log.txt",
   System.IO.FileMode.Create);
                engine.SetStandardOutput(fs);
            }
            
try
            {
                engine.ExecuteFile(
"test.py");
            }
            
catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }          
        }

在test.py中可以用脚本修改主窗口属性,添加控件,添加鼠标事件等。

import clr
clr.AddReferenceByPartialName(
"System.Windows.Forms")
clr.AddReferenceByPartialName(
"System.Drawing")
clr.AddReferenceByPartialName(
"IronPython")

from System.Windows.Forms import *
from System.Drawing import *

win.Text
="中文"
win.MaximizeBox
=False
win.Opacity
=0.9
win.ShowIcon
=False
win.TopMost
=True
#win.WindowState=FormWindowState.Minimized
MessageBox.Show(win.WindowState.ToString())

def click(f, a):
    l 
= Label(Text = "Hello")
    l.Location 
= a.Location
    l.AutoSize 
= True
    l.ForeColor 
= Color.Red
    f.Controls.Add(l)

win.Click 
+= click

def buttonClick(f,a):
  MessageBox.Show(f.Text)

b
=Button(Text="按钮")
b.Click 
+= buttonClick
win.Controls.Add(b)

for i in win.Controls: i.Font = Font("Verdana"9)

源代码下载