Defining Simple Message Boxes
Message boxes (created using the
MessageBox
class) are extremely useful for displaying short messages
and getting canned responses. Depending on the buttons you provide, a user could tell you that the
application should retry an operation or answer yes to simple questions. If you need a little more input,
you can always rely on an input box (created with the
InputBox()
method of the
Interaction
class).
Of course, an input box is still limited to a single field, but even so, it does extend the kinds of input
you can receive from the user.
Listing 17-3 demonstrates both the
MessageBox.Show()
and
InputBox()
methods. In addition,
you’ll see how to implement the
__doc__()
method that most IronPython developers rely upon to
obtain information about your extension. The section “Considering Developer Help” in Chapter 16
provides additional information about developer help needs.
548592c17.indd 368
2/24/10 12:49:35 PM
www.finebook.ir
Using Visual Basic.NET for User Interface Support
❘
369
The content of the
Interaction
class is something that some Visual
Basic.NET developers tend to forget. These methods, such as
Beep()
, are useful
in IronPython. Visual Basic.NET developers get these features automatically as
part of the
Microsoft.VisualBasic
namespace. Other language developers,
such as C#, can use these features, too, but will need to add a reference to
Microsoft.VisualBasic.DLL
and provide the proper
using
statements.
LISTINg 17-3:
Working with simple message boxes
Imports System.Windows.Forms
Public Class Dialogs
Public Function ShowMessage(ByVal Msg As String) As String
Return MessageBox.Show(Msg).ToString()
End Function
Public Function ShowMessage(ByVal Msg As String, _
ByVal Title As String) As String
Return MessageBox.Show(Msg, Title).ToString()
End Function
Public Function ShowMessage(ByVal Msg As String, ByVal Title As String, _
ByVal Buttons As Int16) As String
Return MessageBox.Show(Msg, Title, CType(Buttons, MessageBoxButtons) _
).ToString()
End Function
Public Function ShowMessage(ByVal Msg As String, ByVal Title As String, _
ByVal Buttons As Int16, ByVal Icon As Int16 _
) As String
Return MessageBox.Show(Msg, Title, CType(Buttons, MessageBoxButtons), _
CType(Icon, MessageBoxIcon)).ToString()
End Function
Public Function ShowMessage(ByVal Msg As String, ByVal Title As String, _
ByVal Buttons As Int16, ByVal Icon As Int16, _
ByVal DefaultButton As Int16) As String
Return MessageBox.Show(Msg, Title, CType(Buttons, MessageBoxButtons), _
CType(Icon, MessageBoxIcon), _
CType(DefaultButton, MessageBoxDefaultButton) _
).ToString()
End Function
Public Function GetInput(ByVal Msg As String, ByVal Title As String)
Return InputBox(Msg, Title, “Type a value”)
continues
548592c17.indd 369
2/24/10 12:49:35 PM
www.finebook.ir
Do'stlaringiz bilan baham: |