Winforms - Application get's stuck when minimized

170 views Asked by At

Just recently I was using a WPF Textbox in Winforms using elementhost. I loaded a large text file with at least 100,000 + characters and over 2,000 lines. It opens the file and adds the text to the wpf textbox normally and I can easily scroll through the textbox. When I minimize the program while I've loaded this document, the program gets stuck and it takes quite a while atleast 1 minutes or more sometimes to maximize back. Nothing wrong with the document or the way the program open the document I just don't understand what's wrong with it. What can be the problem if so, is anyone able to solve this.

I debugged the program and there are no debug errors just performance I guess but it loads and opens fine just when I minimize.

Code for Opening a File:

    ''
    Dim WpfTest1 As New Sp.Tb
    Dim ElementHost1 As System.Windows.Forms.Integration.ElementHost = Me.Controls("ElementHost1")
    Dim TheTextBox As System.Windows.Controls.TextBox = CType(ElementHost1.Child, Tb).ctrl_TextBox
    ''
    Dim OFD As New OpenFileDialog
    OFD.Title = "Open"
    OFD.Filter = "Text Documents (*.txt) | *.txt|All Files |*.*"

    If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
        Using sr As New StreamReader(OFD.FileName, Encoding.Default)
            TheTextBox.Text = sr.ReadToEnd
            Var.SaveLocation = OFD.FileName
            sr.Close()
            Var.MadeChanges = False
            lbl_LastSaved.IsLink = True
        End Using
        Me.Text = System.IO.Path.GetFileNameWithoutExtension(OFD.FileName) + " - " + ProductName
        lbl_LastSaved.Text = "Last Saved " + System.IO.File.GetLastWriteTime(Var.SaveLocation).ToString("f")
        SaveRecentFile(Var.SaveLocation)
    End If
1

There are 1 answers

0
Zer0 On

The problem was SCROLLBARS and their visibility.

Before:

VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Visible"

After:

 VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto"

For some reason this fixed it.