【发布时间】:2016-12-23 23:22:42
【问题描述】:
我正在尝试为用户生成一条返回缺失清单项目列表的消息。我的问题:有没有办法构建一条消息,然后可以将其传递给包含新行的 MessageBox。我考虑过重载该方法以接受各种数量的单个消息,但必须有一种更优雅的方法来做到这一点。下面是我设计的用于处理此消息收集、显示和将来导出为更方便格式的类。
Public Class clsChecklistMissingItems
Private Shared iWrong As Integer = 0 'Number of items wrong.
Private Shared sMissingItems() As String 'Will use the number of items wrong.
Public Shared Sub CollectItem(ByVal mess As String) 'Saves the message passed to it.
ReDim Preserve sMissingItems(iWrong) 'Resize the array based on the counter.
sMissingItems(iWrong) = mess 'Assign the message to the missing items string array.
iWrong = iWrong + 1 'Increment the counter (may give us +1
End Sub
Public Sub DisplayList() 'Displays the message at the end of the execution.
'Can this be generated procedurally?
MessageBox.Show("There were " & iWrong & " missing or incorrect items." & vbNewLine &
sMissingItems(iWrong))
End Sub End Class
我的替代解决方案是编写一个格式类似于文本框的表单,其行为类似于文本框,但具有所有描述的功能。
【问题讨论】:
-
也许会以模态形式显示具有该信息的另一个表单,以便用户在继续之前需要关闭它?
-
不要在标题中添加“SOLVED”。您通过发布答案表明您已经解决了问题!
标签: vb.net messagebox