Several days ago, we share our advice about 70-526 preparation  and the main topic areas on 70-526 exam .To help us better study MCTS 70-526, here we will share our exam notes on .net 2.0-Windows Based Client Development, which you can take as free eBook or Pdf online, but not braindumps .First of all, what I should emphasize is although the TechNotes cover .net 2.0,they can not replace any MS Press self-paced training kit or other .net 2.0 books .It just can play a role of study guide or help you better understand 70-526 topic areas .Get down to business, now we begin to talk about the MCTS 70-526 objective study notes(1)– Create and use custom dialog boxes in Windows Forms applications.. If there is confusion or mistake, please let me know.

It is noted that all of the technotes are based on Visual Basic 2005.

I remember the first time I needed to create a dialog box in a .NET application that I was writing in C#. Being a long-time Visual Basic programmer, I assumed that this could easily be accomplished by using a dialog box template included with Visual Studio.NET. To my surprise, no such form template existed for C#, although one does for Visual Basic 2005. After wading through several books and Web pages filled with information on Windows Forms 2.0 programming, a basic set of steps became apparent to me for manually converting a .NET form into a Windows dialog box:
1. Add a Form to your .NET project and name it “DialogBoxForm”.
2. Drop two buttons in the lower right-hand area of the Form and name them “OKButton” and “CancelButton”.
3. Change the following properties of the Form to adjust its appearance and behavior to be like a standard dialog box:\

Property Value Description
AcceptButton OK button instance Causes form to return value DialogResult.OK. Only used on modal dialog boxes.
CancelButton Cancel button instance Causes form to return value DialogResult.Cancel. Only used on modal dialog boxes.
FormBorderStyle FixedDialog Create a non-sizable form with no control box on the title bar.
HelpButton True The Help button appears in the caption bar next to the Close button. The ControlBox property must be True for these buttons to be visible.
MaximizeBox False Hide the Maximize button in the title bar.
MinimizeBox False Hide the Minimize button in the title bar.
ShowIcon False The title bar icon is not visible in a dialog box.
ShowInTaskBar False Do not indicate the presence of the form on the Windows Task Bar.
Start Position CenterParent The initial position of a dialog box is over its parent form.
Size As Needed The fixed size needed for the dialog box.

 

These properties can be set using the Properties window for the form, or using code placed in the Form’s Load event:
        Me.AcceptButton = OKButton
        Me.CancelButton = CancelButton
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
        Me.HelpButton = True
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.ShowInTaskbar = False
        Me.ShowIcon = False
        Me.StartPosition = FormStartPosition.CenterParent
4. Add the following button click event handlers to the Form:
    Private Sub OKButton_Click(ByVal sender As Object, _

     ByVal e As EventArgs)
        ‘ User clicked the OK button
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub CancelButton_Click(ByVal sender As Object, _

     ByVal e As EventArgs)
        ‘ User clicked the Cancel button
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
5. Add properties that you need to move data into and out of the dialog box as you would for any Form:
    Private _LoginName As String
    Private _LoginPassword As String

    Public Property LoginName() As String
        Get
            Return _LoginName
        End Get
        Set(ByVal value As String)
            _LoginName = value
        End Set
    End Property

    Public Property LoginPassword() As String
        Get
            Return _LoginPassword
        End Get
        Set(ByVal value As String)
            _LoginPassword = value
        End Set
    End Property
6. Show the dialog box modally by calling the ShowDialog() of the form:
    Public Sub ShowDialogBox()
        Dim dialog As New DialogBoxForm

        dialog.LoginName = “JDMurray”
        dialog.LoginPassword = String.Empty

        If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Debug.WriteLine(“Login Name: ” & dialog.LoginName)
            Debug.WriteLine(“Password: ” & dialog.LoginPassword)
        Else
            ‘ User clicked the Cancel button
        End If
    End Sub
7. To show the dialog box modelessly, call the Show() method of DialogBoxForm instead. You will need to add an event handler to the Close event of DialogBoxForm to know when the user closes the dialog box:
    Public Sub ShowDialogBox()
        Dim dialog As DialogBoxForm = New DialogBoxForm
        dialog.LoginName = “JDMurray”
        dialog.Password = String.Empty
        AddHandler dialog.FormClosed, AddressOf dialog_FormClosed
        dialog.Show()

        ‘ The Show() method returns immediately
    End Sub

    Private Sub dialog_FormClosed(ByVal sender As Object, _

     ByVal e As FormClosedEventArgs)
        ‘ This method is called when the user closes the dialog box
    End Sub

Thanks for your reading

this is from http://www.techexams.net/blogs/net/70-526/creating-dialog-boxes-in-net/

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter