压缩vb.net代码
我有以下代码:
Private Sub txtFileFromLocation_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
MachineNameUIDisabled()
ServiceNameUIDisabled()
ToLocationUIDisabled()
btnSubmitUIDisabled()
lblStatusClear()
End Sub
Private Sub txtMachineName_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
ServiceNameUIDisabled()
ToLocationUIDisabled()
btnSubmitUIDisabled()
lblStatusClear()
End Sub
Private Sub txtServiceName_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
ToLocationUIDisabled()
btnSubmitUIDisabled()
lblStatusClear()
End Sub
Private Sub txtFilesToLocation_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
btnSubmitUIDisabled()
lblStatusClear()
End Sub
我希望将其合并到一个子程序中,而不需要任何重复代码(所有子程序当前都包含 btnSubmitUIDisabled()
和 lblStatusClear()
)
我想过一个 CASE
语句,但也会有重复的代码。这是一个 WPF 应用程序,所有“TextChanged”事件都位于 xaml 中,因此每个子末尾没有“Handles”。
提前致谢。
I have the following code:
Private Sub txtFileFromLocation_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
MachineNameUIDisabled()
ServiceNameUIDisabled()
ToLocationUIDisabled()
btnSubmitUIDisabled()
lblStatusClear()
End Sub
Private Sub txtMachineName_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
ServiceNameUIDisabled()
ToLocationUIDisabled()
btnSubmitUIDisabled()
lblStatusClear()
End Sub
Private Sub txtServiceName_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
ToLocationUIDisabled()
btnSubmitUIDisabled()
lblStatusClear()
End Sub
Private Sub txtFilesToLocation_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
btnSubmitUIDisabled()
lblStatusClear()
End Sub
I am looking to consolidate this into one sub without having any repeating code (all subs currently hold btnSubmitUIDisabled()
and lblStatusClear()
)
I thought about a CASE
statement but that would also have repetitive code. This is a WPF application and all the "TextChanged" events are located in the xaml, thus no "Handles" at the end of each sub.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
伪代码不太像VB 人:
不漂亮,但一种方法。
编辑:我没有提到的一件事是您希望将发送者转换为文本框类型,以便您可以获得 name 属性。
Pseudo code as not that much of a vb guy:
Not pretty but one method.
EDIT: One thing I didn't mention is you would want to cast the sender to a textbox type so that you can get the name property.
如果您希望通过一种方法实现所有内容,那么@spinon 答案是一种方法。另一种方法是编写一个扩展方法来减少需要编写的 OrElse 语句的数量,并使代码更具可读性。
If you want it all in one method then @spinon answer is one way. Another is write an extension method to reduce the amount of OrElse statements you need to write and it makes the code a bit more readable.
一方面,您可以级联调用:
我个人会在这一点上以不同的方式命名它们 - 让方法说出它做什么而不是它反应 - 但这就是只是我和 Visual Studio 之间长期存在的意见分歧。
Well for one thing you can cascade the calls:
I would personally name them differently at that point - make the method say what it does rather than what it reacts to - but that's just a long-running difference of opinion between myself and Visual Studio.