Dialog apply method : Custom Dialog « GUI « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » GUI » Custom Dialog 
13. 68. 6. Dialog apply method
Dialog apply method
 


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class DialogApplyMethod
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class


Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
  Friend WithEvents btnCreate As System.Windows.Forms.Button
  Friend WithEvents lblReturn As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
Me.btnCreate = New System.Windows.Forms.Button()
Me.lblReturn = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'btnCreate
'
Me.btnCreate.Location = New System.Drawing.Point(72144)
Me.btnCreate.Name = "btnCreate"
Me.btnCreate.Size = New System.Drawing.Size(15223)
Me.btnCreate.TabIndex = 0
Me.btnCreate.Text = "Create Dialog Box"
'
'lblReturn
'
Me.lblReturn.Location = New System.Drawing.Point(8872)
Me.lblReturn.Name = "lblReturn"
Me.lblReturn.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(513)
Me.ClientSize = New System.Drawing.Size(292273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblReturn, Me.btnCreate})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

   End Sub

#End Region

  public sub UpdateLabel(str as String)
    lblReturn.Text = str
  end sub

  Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnCreate.Click
    dim dlg as new DialogDemome 
    dlg.EnableApplyButton = false

    dlg.ShowDialog()
    
    if dlg.DialogResult = DialogResult.OK then
      lblReturn.Text = dlg.TextOut
    else
      lblReturn.Text = dlg.DialogResult.ToString()
    end if
  End Sub
End Class

public class DialogDemo 
      inherits Form
  dim btnApply as Button
  dim txt as TextBox
  dim f as Form1
  
  public sub new (f as Form1)
        myBase.New
    me.f = f
    FormBorderStyle = FormBorderStyle.FixedDialog
    ControlBox = false
    MaximizeBox = false
    MinimizeBox = false
    ShowInTaskbar = false
    Size = new Size(400,200)
    StartPosition = FormStartPosition.CenterScreen

    dim btnOK as New Button
    btnOK.Text = "OK"
    btnOK.DialogResult = DialogResult.OK
    btnOK.Location = new Point(50,50)
    Controls.Add(btnOK)
    
    btnApply = new Button()
    btnApply.Text = "Apply"
    btnApply.Location = new Point(150,50)
    btnApply.Enabled = false
    AddHandler btnApply.Click, AddressOf ApplyOnClick
    Controls.Add(btnApply)
    
    dim btnCancel as new Button()
    btnCancel.Text = "Cancel"
    btnCancel.DialogResult = DialogResult.Cancel
    btnCancel.Location = new Point(250,50)
    Controls.Add(btnCancel)

    txt = new TextBox()
    txt.Size = new Size(100,15)
    txt.Location = new Point(150,15)
    AddHandler txt.TextChanged, AddressOf TextBoxChanged
    Controls.Add(txt)
    
  end sub

  private sub ApplyOnClick(sender as Object, e as EventArgs)
    f.UpdateLabel(txt.Text)
    EnableApplyButton = false
  end sub
  
  private sub TextBoxChanged(sender as Object, e as EventArgs)
    dim txt as TextBox = CType(sender,TextBox)
    dim dlg as DialogDemo = CType(txt.Parent,DialogDemo)
    dlg.EnableApplyButton = true  
  end sub

  public property EnableApplyButton as Boolean
    get 
      return btnApply.Enabled
    end get
    set
      btnApply.Enabled = value 
    end set
  end property
  
  public ReadOnly property TextOut as string
    get
      return txt.Text 
    end get
  end property
end class

        
13. 68. Custom Dialog
13. 68. 1. Create Dialog from FormCreate Dialog from Form
13. 68. 2. User defined DialogUser defined Dialog
13. 68. 3. Get Custom dialog returning valueGet Custom dialog returning value
13. 68. 4. Login DialogLogin Dialog
13. 68. 5. About DialogAbout Dialog
13. 68. 6. Dialog apply methodDialog apply method
13. 68. 7. Custom dialog with custom classCustom dialog with custom class
13. 68. 8. Dialog with propertiesDialog with properties
w___w__w_.j__av_a2_s___._c___o___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.