我在其中创建了一个带有树视图的usercontrol。如果我在usercontrol的onload处理程序中添加节点,则将填充树视图。但在那之后(例如,我单击其父窗体中的按钮),树视图将不会刷新。我可以看到节点在内存中更新,但它无法在屏幕上显示。我在添加节点后调用了刷新/更新。任何建议表示赞赏。
答案 0 :(得分:0)
我根据你的描述进行了快速测试,看起来很好。
的UserControl1
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class UserControl1
Inherits System.Windows.Forms.UserControl
'UserControl overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
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.TreeView1 = New System.Windows.Forms.TreeView
Me.SuspendLayout()
'
'TreeView1
'
Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Fill
Me.TreeView1.Location = New System.Drawing.Point(0, 0)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.Size = New System.Drawing.Size(150, 150)
Me.TreeView1.TabIndex = 0
'
'UserControl1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.Controls.Add(Me.TreeView1)
Me.Name = "UserControl1"
Me.ResumeLayout(False)
End Sub
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
End Class
Public Class UserControl1
Public Sub AddNewNode(ByVal text As System.String)
TreeView1.Nodes.Add(text)
End Sub
End Class
将usercontrol放在带有按钮的表单上
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UserControl11.AddNewNode(Now.ToString)
End Sub
End Class
如果您正在看到正确的绘画,那么请查看父表单中的任何图形处理,然后是usercontrol,然后查看usercontrol中的控件。我们真的需要更多信息。
答案 1 :(得分:0)
谢谢你,戴夫。我想到了。我错误地将usercontrol两次放到我的表单中(我不记得我是怎么做的)。我操作的那个在另一个下面。这就是为什么我看不到它。抱歉浪费你的时间。