vb.net表单加载和渲染速度太慢

时间:2017-08-11 19:22:17

标签: vb.net forms

我有一个mdi父表单,当点击屏幕上的特定按钮时,会打开一个新的子表单。当这个表单加载时,它需要调用数据库来检索信息,问题是表单需要花费很多时间才能加载,比如15秒,加载子中没有太多的代码,我也是试图从load事件中删除数据库代码,虽然它确实使它更快一点,但仍然需要一些时间来加载,有没有办法解决这个问题?

这是我的表格

enter image description here

这是我的代码

Public Class Deposito
Dim FormPadre As MDICajero = New MDICajero
Private monedas As ArrayList = New ArrayList
Private Sub Deposito_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.WindowState = FormWindowState.Maximized
    FormPadre = Me.MdiParent
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Dim ProximoForm As MenuPrincipal = New MenuPrincipal
    FormPadre.LimpiarForm()
    ProximoForm.MdiParent = FormPadre
    ProximoForm.WindowState = FormWindowState.Maximized
    ProximoForm.Show()
    ProximoForm.CargaMenu(1)
End Sub

Private Sub BDepositar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BDepositar.Click
    Dim dato As Emovimientos = New Emovimientos
    dato.monto = montodeposito.Text
    dato.idcuenta = nrocuenta.Text
    dato.fecha = fechacobro.Value

End Sub End class

之前我曾使用过Java,并且从未在表单之间看到过如此多的加载时间,即使从数据库中检索信息也是如此。

编辑:在构造函数中添加了几行以使表单加载更快,但渲染过程仍然存在错误。

Sub New()
    Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)
    Me.SetStyle(ControlStyles.UserPaint, True)
    InitializeComponent()

End Sub

编辑2:在MDI父表单上,我使用了在向解决方案添加mdi表单时自动编写的相同代码,我添加的唯一内容是按下按钮打开子表单时的事件: / p>

Private Sub BRetiro_Click(sender As System.Object, e As System.EventArgs) Handles BRetiro.Click
    Dim ProximoForm As Retiro = New Retiro
    Me.LimpiarForm()
    ProximoForm.MdiParent = Me
    ProximoForm.WindowState = FormWindowState.Maximized
    ProximoForm.Show()
End Sub

这是" LimpiarForm"的代码。功能:

 Public Sub LimpiarForm()
    'borro todos los form hijos para no ocupar memoria, debe ser lo primero que tengo que hacer
    Dim num As Integer
    For num = 0 To Me.MdiChildren.Count - 1
        Dim a = Me.MdiChildren(num)
        a.Dispose()
    Next
End Sub

0 个答案:

没有答案