2012-05-09 68 views
0

我有一个主窗体的窗体项目。有一个文本框离开事件会打开一个新窗体。在新的表单加载事件中,我有一个组合框项目循环来填充组合框项目。如果在主表单上运行,但在第二个表单上运行,则它工作得很好。为什么当通过主窗体中的textbox_leave事件打开窗体时,辅助窗体上的组合框不会填充? 这是假事件组合框没有被填充

Private Sub tbChartTitle_Leave(sender As Object, e As System.EventArgs) Handles tbChartTitle.Leave 
    If Not tbChartTitle.Text = Nothing Then 
     frmTitleAttributes.Show() 
    End If 
End Sub 

这是填充第二窗体上的组合框的一个代码(它如果主窗体上的组合框运行Works)

Private Sub frmTitleAttributes_Load(sender As Object, e As System.EventArgs) Handles Me.Load 
    InitializeComponent() 
    AddFonts() 
End Sub 
Private Sub AddFonts() 
    ' Get the installed fonts collection. 
    Dim allFonts As New Drawing.Text.InstalledFontCollection 
    ' Get an array of the system's font familiies. 
    Dim fontFamilies() As FontFamily = allFonts.Families 

    ' Display the font families. 
    For i As Integer = 0 To fontFamilies.Length - 1 
     cbxTitleFonts.Items.Add(fontFamilies(i).Name) 
    Next 
End Sub 

回答

0

确保你看你的表单(使用断点)

,你也可以尝试将它称之为在Shown事件之后Load处理器被击中

Private Sub frmTitleAttributes_Shown(sender as Object, e as EventArgs) _ 
    Handles frmTitleAttributes.Shown 

    AddFonts() 

End Sub 
+0

谢谢。我发现调用load load中的initializecomponent会导致问题 – dinotom