水如烟

                 顺其自然,水到渠成 LzmTW

文或代码皆是面向初学者.我是爱好者,也是初学者.那些"文章",只按自己理解写,我是不知术语名词的.所以只供参考,也仅供参考.

导航

异类HOW TO:适时弹出指示框(五)

Posted on 2006-05-30 12:01  水如烟(LzmTW)  阅读(823)  评论(0编辑  收藏  举报
Author:水如烟

指示框:
MessageForm.Designer.vb
Namespace ApplicationBase
    
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial 
Class MessageForm
        
Inherits System.Windows.Forms.Form

        
'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            
If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            
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.
        <System.Diagnostics.DebuggerStepThrough()> _
        
Private Sub InitializeComponent()
            
Me.LabelMessage = New System.Windows.Forms.Label
            
Me.SuspendLayout()
            
'
            'LabelMessage
            '
            Me.LabelMessage.AutoSize = True
            
Me.LabelMessage.Location = New System.Drawing.Point(129)
            
Me.LabelMessage.Name = "LabelMessage"
            
Me.LabelMessage.Size = New System.Drawing.Size(8312)
            
Me.LabelMessage.TabIndex = 0
            
Me.LabelMessage.Text = "进行中 "
            
'
            'MessageForm
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
            
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            
Me.ClientSize = New System.Drawing.Size(56771)
            
Me.ControlBox = False
            
Me.Controls.Add(Me.LabelMessage)
            
Me.MaximumSize = New System.Drawing.Size(57598)
            
Me.MinimumSize = New System.Drawing.Size(57598)
            
Me.Name = "MessageForm"
            
Me.ShowInTaskbar = False
            
Me.Text = "请稍候"
            
Me.TopMost = True
            
Me.ResumeLayout(False)
            
Me.PerformLayout()

        
End Sub
        
Private WithEvents LabelMessage As System.Windows.Forms.Label
    
End Class
End Namespace

MessageForm.vb
Imports System.Windows.Forms

Namespace ApplicationBase

    
Friend Class MessageForm
        
Protected Delegate Sub SetControlText(ByVal ctr As Control, ByVal s As String)

        
Private CanClose As Boolean = False

        
Protected Sub OnSetControlText(ByVal ctr As Control, ByVal s As String)
            
If ctr.InvokeRequired Then
                
Dim d As New SetControlText(AddressOf OnSetControlText)
                
Me.Invoke(d, New Object() {ctr, s})
            
Else
                ctr.Text 
= s
            
End If
            Application.DoEvents()
        
End Sub

        
Private Sub WaitingForm_FormClosing(ByVal sender As ObjectByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            e.Cancel 
= Not CanClose
        
End Sub

        
Public Sub SetFormText(ByVal s As String)
            OnSetControlText(
Me, s)
        
End Sub

        
Public Sub SetMessage(ByVal s As String)
            OnSetControlText(
Me.LabelMessage, s)
        
End Sub

        
Public Sub SetMessage(ByVal format As StringByVal args() As Object)
            SetMessage(
String.Format(format, args))
        
End Sub

        
Public Sub SetCanClose(ByVal yes As Boolean)
            CanClose 
= yes
        
End Sub
    
End Class

End Namespace

ProgressForm.Designer.vb
Namespace ApplicationBase

    
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial 
Class ProgressForm
        
Inherits ApplicationBase.MessageForm

        
'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            
If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            
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.
        <System.Diagnostics.DebuggerStepThrough()> _
        
Private Sub InitializeComponent()
            
Me.ProgressBar = New System.Windows.Forms.ProgressBar
            
Me.SuspendLayout()
            
'
            'ProgressBar
            '
            Me.ProgressBar.Location = New System.Drawing.Point(1635)
            
Me.ProgressBar.Name = "ProgressBar"
            
Me.ProgressBar.Size = New System.Drawing.Size(54123)
            
Me.ProgressBar.Step = 1
            
Me.ProgressBar.Style = System.Windows.Forms.ProgressBarStyle.Marquee
            
Me.ProgressBar.TabIndex = 1
            
'
            'ProgressForm
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
            
Me.ClientSize = New System.Drawing.Size(56771)
            
Me.Controls.Add(Me.ProgressBar)
            
Me.Name = "ProgressForm"
            
Me.Controls.SetChildIndex(Me.ProgressBar, 0)
            
Me.ResumeLayout(False)
            
Me.PerformLayout()

        
End Sub
        
Private WithEvents ProgressBar As System.Windows.Forms.ProgressBar

    
End Class

End Namespace

ProgressForm.vb
Namespace ApplicationBase

    
Friend Class ProgressForm

    
End Class

End Namespace

WaitingForm.vb
Namespace ApplicationBase
    
Public Class WaitingForm
        
Private gMessageForm As MessageForm
        
Private Shared gCurrentForm As WaitingForm
        
Public Shared ReadOnly Property CurrentForm() As WaitingForm
            
Get
                
Return gCurrentForm
            
End Get
        
End Property

        
Sub New(ByVal FormType As MessageFormType)
            
Select Case FormType
                
Case MessageFormType.Message
                    gMessageForm 
= New MessageForm
                
Case MessageFormType.Progress
                    gMessageForm 
= New ProgressForm
            
End Select
            gCurrentForm 
= Me
        
End Sub

        
Public Sub ReceiveMessage(ByVal s As String)
            ReceiveMessage(s, 
False)
        
End Sub

        
Public Sub ReceiveMessage(ByVal s As StringByVal IsTitle As Boolean)
            
If IsTitle Then
                gMessageForm.SetFormText(s)
            
Else
                gMessageForm.SetMessage(s)
            
End If
        
End Sub

        
Public Sub ReceiveMessage(ByVal format As StringByVal args() As Object)
            ReceiveMessage(
format, args, False)
        
End Sub

        
Public Sub ReceiveMessage(ByVal format As StringByVal args() As ObjectByVal IsTitle As Boolean)
            ReceiveMessage(
String.Format(format, args), IsTitle)
        
End Sub

        
Public Sub Show()
            gMessageForm.Show()
        
End Sub

        
Public Sub Hide()
            gMessageForm.Hide()
        
End Sub

        
Public Sub Close()
            gMessageForm.SetCanClose(
True)
            gMessageForm.Close()
            gMessageForm 
= Nothing
        
End Sub

        
Public ReadOnly Property IsDisposed() As Boolean
            
Get
                
If gMessageForm Is Nothing Then Return True
                
Return gMessageForm.IsDisposed
            
End Get
        
End Property

        
'//
        Private Shared gDefaultForm As WaitingForm
        
Private Shared gDefaultType As MessageFormType = MessageFormType.Message
        
Public Shared ReadOnly Property DefaultForm() As WaitingForm
            
Get
                GetDefaultForm()
                
Return gDefaultForm
            
End Get
        
End Property

        
Private Shared Sub GetDefaultForm()
            
If gDefaultForm Is Nothing OrElse gDefaultForm.IsDisposed Then
                gDefaultForm 
= New WaitingForm(gDefaultType)
            
End If
        
End Sub

        
Public Shared Sub SetDefaultFormType(ByVal formtype As MessageFormType)
            
If formtype <> gDefaultType Then
                
If gDefaultForm IsNot Nothing Then gDefaultForm.Close()
                gDefaultType 
= formtype
            
End If
        
End Sub

    
End Class
End Namespace

Namespace ApplicationBase
    
Public Enum MessageFormType
        Message
        Progress
    
End Enum
End Namespace