Results 1 to 13 of 13

Thread: [2005] Showing another form

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    [2005] Showing another form

    I have a loading form that i want to show when i'm reading something from the serial port. My only problem is that i'm not 100% sure what's with the new stuff like delegates, but i've got it to work with a MyDelegate sub. But to invoke on the loading form, it throws an exception that the window needs a handle before you can invoke... So if I make it visible and then hide it again in the main form load, it works... Any ideas how i could avoid the flicker of the form showing and hiding and how it actually should be done?

    Thanks


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Showing another form

    Can't you just call the show and hide method?
    Form1.Show()
    Form1.Hide()
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [2005] Showing another form

    Here is what i have so far... Any comments would be useful
    Attached Files Attached Files


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Showing another form

    There is no need to call the visible properties in the for load.
    Just change you Show and Hide functions to call

    VB Code:
    1. Private Sub ShowRead()
    2.         fRead.Show()
    3.     End Sub
    4.  
    5.     Private Sub HideRead()
    6.         fRead.Hide()
    7.     End Sub
    8.  
    9.     Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    10.         If Serial.IsOpen = True Then
    11.             Serial.Close()
    12.         End If
    13.  
    14.         Index = 0
    15.  
    16.         fRead.pbRead.Minimum = 0
    17.         fRead.pbRead.Maximum = 63
    18.         fRead.pbRead.Value = 0
    19.  
    20.         Try
    21.             With Serial
    22.                 .BaudRate = 9600
    23.                 .Parity = IO.Ports.Parity.None
    24.                 .DataBits = 8
    25.                 .StopBits = IO.Ports.StopBits.One
    26.             End With
    27.             Serial.Open()
    28.         Catch ex As Exception
    29.             MsgBox(ex.ToString)
    30.         End Try
    31.     End Sub
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  5. #5

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [2005] Showing another form

    I get an exception :

    Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

    on this line :

    fRead.Invoke(New myDelegate(AddressOf ShowRead))


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Showing another form

    Question, why are you using delegates to show the form? Why not just call the show method in your DataRecieved sub like so
    VB Code:
    1. Private Sub DataReceived( _
    2.        ByVal sender As Object, _
    3.        ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
    4.        Handles Serial.DataReceived
    5.  
    6.         If fRead.Visible = False Then
    7.             fRead.Show()
    8.         End If
    9.  
    10.         fRead.pbRead.Invoke(New myDelegate(AddressOf ChangePB))
    11.  
    12.         Tdata(Index) = Serial.ReadByte
    13.         Index += 1
    14.  
    15.         If Index = 64 Then
    16.             Index = 0
    17.  
    18.             Call Display()
    19.         End If
    20.     End Sub
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  7. #7

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [2005] Showing another form

    Cross-thread operation not valid: Control 'frmRead' accessed from a thread other than the thread it was created on.


    Has someone helped you? Then you can Rate their helpful post.

  8. #8

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [2005] Showing another form

    Have I worded it wrong? I can't be the first to run into this, can I?


    Has someone helped you? Then you can Rate their helpful post.

  9. #9

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [2005] Showing another form

    Someone? Anyone? Please?


    Has someone helped you? Then you can Rate their helpful post.

  10. #10

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [2005] Showing another form

    Please?


    Has someone helped you? Then you can Rate their helpful post.

  11. #11
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Showing another form

    Here is something similiar out of an application that I have done.

    My ShowProcessing.vb class
    Code:
    Imports System.ComponentModel
    
    Public Class ShowProcessing
        Implements IDisposable
    
        Private _TextToDisplay As String
        Private WithEvents _bw As New BackgroundWorker
    
    #Region " IDisposable Support "
        Private disposedValue As Boolean = False        ' To detect redundant calls
    
        ' IDisposable
        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then
    
                End If
    
                _bw.Dispose()
            End If
            Me.disposedValue = True
        End Sub
        ' This code added by Visual Basic to correctly implement the disposable pattern.
        Public Sub Dispose() Implements IDisposable.Dispose
            ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
    #End Region
    
    #Region " Property Declarations "
        Friend Property TextToDisplay() As String
            Get
                Return _TextToDisplay
            End Get
            Set(ByVal value As String)
                _TextToDisplay = value
            End Set
        End Property
    #End Region
    
        Public Sub New()
            _bw.WorkerSupportsCancellation = True
        End Sub
    
        Friend Sub StartProcessing()
            _bw.RunWorkerAsync()
        End Sub
    
        Friend Sub StopProcessing()
            _bw.CancelAsync()
        End Sub
    
        Private Sub _bw_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles _bw.DoWork
            Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
    
            e.Result = DisplayForm(worker, _TextToDisplay, e)
        End Sub
    
        Private Function DisplayForm(ByVal worker As BackgroundWorker, ByVal inText As String, ByVal e As System.ComponentModel.DoWorkEventArgs) As Boolean
            Dim frm As New frmProcessing
    
            With frm
                .Text = inText
                .ShowDialog(worker, e)
                .Dispose()
            End With
        End Function
    End Class
    My ProgressBar form:
    Code:
    Public Class frmProcessing
    
        Private _worker As System.ComponentModel.BackgroundWorker
        Private _e As System.ComponentModel.DoWorkEventArgs
    
        Private Sub frmProcessing_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            _e.Cancel = True
        End Sub
    
        Private Sub frmProcessing_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With ProgressBar1
                .Minimum = 0
                .Maximum = 100
                .Value = 0
            End With
    
            With Timer1
                .Interval = 500
                .Start()
            End With
    
            Cursor = Cursors.WaitCursor
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If _worker.CancellationPending Then
                Me.Close()
            End If
    
            If ProgressBar1.Value = 100 Then
                ProgressBar1.Value = 0
            Else
                ProgressBar1.Value += 1
            End If
        End Sub
    
        Public Overloads Function ShowDialog(ByVal worker As System.ComponentModel.BackgroundWorker, ByVal e As System.ComponentModel.DoWorkEventArgs) As System.Windows.Forms.DialogResult
            _worker = worker
            _e = e
            MyBase.ShowDialog()
        End Function
    End Class
    My.Settings.Signature = String.Empty

  12. #12
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Showing another form

    The example above is shown by FormA when it starts a SQL Stored Procedure that takes about 5 minutes to run. I just wanted the user to understand that it was still working.

    That should give you a push in the right direction.

    PS - Why all of the Delegates in your code? Is there something I am missing?
    My.Settings.Signature = String.Empty

  13. #13

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [2005] Showing another form

    I had the Delegates, so I could change the values of the label and the progressbar without getting the errors I've written above (Cross-thread operation not valid) I might be going about this the wrong way... I'll look at your code, try and compare. So thanks, I'll have a look


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width