简化VB中的多个类似“私人订阅”

时间:2019-04-23 06:59:39

标签: vba

我正在编写一个VB程序,该程序具有多个位置,当用户将鼠标悬停在某个项目上时,会显示相同的图像。

目前,我有:

Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
    PictureBox1.Image = Image.FromFile(picturePath)
End Sub

Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove
    PictureBox2.Image = Image.FromFile(picturePath)
End Sub

Private Sub PictureBox3_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox3.MouseMove
    PictureBox3.Image = Image.FromFile(picturePath)
End Sub

Private Sub PictureBox4_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox4.MouseMove
    PictureBox4.Image = Image.FromFile(picturePath)
End Sub

Private Sub PictureBox5_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox5.MouseMove
    PictureBox5.Image = Image.FromFile(picturePath)
End Sub

Private Sub PictureBox6_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox6.MouseMove
    PictureBox6.Image = Image.FromFile(picturePath)
End Sub

Private Sub PictureBox7_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox7.MouseMove
    PictureBox7.Image = Image.FromFile(picturePath)
End Sub

这很好,但是,我希望压缩我的代码。当然,有一种方法可以将其仅分为1个或2个私有订阅。

请注意,这只是我的代码的一部分。

对象的名称很容易命名为PictureBox1PictureBox2等。

致谢

雨果。

1 个答案:

答案 0 :(得分:1)

from urllib.request import urlopen
from bs4 import BeautifulSoup

url = urlopen('https://openphish.com/feed.txt')
bs = BeautifulSoup(url.read(), 'html.parser' )

import re
domain_list = re.findall(re.compile('http[s]?://([^/]*)/'), bs.text)
print('\n'.join(domain_list))