可以拆分 Visual Basic (.NET / 2010) 文件以提高可读性吗?

发布于 2024-09-29 14:29:43 字数 274 浏览 0 评论 0原文

我正在使用 Visual Basic 2010 编写一个程序。它是一个 HMI(人机界面),因此具有一整套按钮,仅用于向其他设备发送命令。结果,有一大堆用于单击按钮的事件处理程序,这些事件处理程序无法真正分解为模块(除非我对模块的理解是错误的)。

本质上,我希望能够将所有事件处理程序(例如按钮按下)移动到不同的文件。这可以完成吗?或者它们保留在“MainWindow.xaml.vb”中很重要吗? (我的所有按钮都位于一个全屏窗口中,有些按钮被选项卡隐藏)。

谢谢,

--埃里克·T

I'm writing a program in Visual Basic 2010. It's a HMI (Human-Machine Interface) and therefore has a whole whack of buttons that just send commands to other devices. As a result, there are a huge pile of event handlers for clicking buttons that can't really be broken down into modules (unless my understanding of modules is wrong).

Essentially, I'd like to be able to move all the event handlers, for, say, button presses to a different file. Can this be done or is it important that they stay in "MainWindow.xaml.vb"? (All my buttons reside in one fullscreen window, some are hidden by tabs).

Thanks,

--Erik T

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

多情癖 2024-10-06 14:29:44

如果需要,您可以使用部分类将它们拆分为单独的文件。

You can use Partial Classes to split these into separate files, if required.

烟若柳尘 2024-10-06 14:29:44

您能否将某些功能分离到自定义控件中?甚至可能根据一些外部数据动态创建按钮?

Could you separate some of the functionality into custom controls instead? Possibly even create the buttons on the fly based on some external data?

撩发小公举 2024-10-06 14:29:44

对于 UI 的模块化,您可以探索 此处描述的 WPF/SL 的组合功能 以及此处 的帮助程序和示例。但这是一个非常不同的架构,如果您已经拥有大量代码,则可能是一次重大重构。

对于按钮,您应该能够使用隐藏大部分事件处理程序的命令。 此处了解有关命令的信息。

For the modularity of the UI, you could explore the composition capacities of WPF/SL described here and with helpers and examples here . But it`s a really different architecture, and might be a major refactoring if you already have a lot of code.

For the buttons, you should be able to use commanding that should hide most of your event handlers. Read about commanding here.

魂归处 2024-10-06 14:29:43

您可以使用部分类将类定义分解为多个文件,这可能有助于组织您的代码。

上面的链接将有助于准确解释如何使用部分类。以下链接将向您展示 VB.NET 语法(以及如何使用类设计器来拆分内容):

如何:将类拆分为部分类

You can use Partial Classes to break up your class definition into multiple files which might help organize your code.

The link above will help explain exactly how to use Partial Classes. The following link will show you the VB.NET Syntax (and how to use Class Designer to split things up):

How to: Split a Class into Partial Classes

微暖i 2024-10-06 14:29:43

我喜欢使用区域来隐藏代码
(代码荧光笔不会做这种事情,所以我会使用图像)
alt text

请记住,这只是隐藏 VS 中的代码,文件仍然完好无损,编译器将忽略#Region#End Region

I like to use regions to hide code
(the code highlighter dose not do this kinda thing so ill use an image)
alt text

Keep in mind that this is only hiding the code in VS the file is still compleatly intact and the compiler will just ignore the #Region and #End Region lines

与之呼应 2024-10-06 14:29:43

当然使用部分类。查看这篇文章,

http://visualbasic.about.com/od/usingvbnet/a /partclses.htm

Sure use partial class. Check this article,

http://visualbasic.about.com/od/usingvbnet/a/partclses.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文