如何在以编程方式创建的按钮上显示文本?

时间:2016-10-20 11:51:56

标签: vb.net visual-studio

我已经以编程方式创建了按钮,并且它们具有文本值但由于某些原因无法显示。

Dim NodeButton As New Control    
NodeButton.Name = "Button" & NodeID   
NodeButton.BackColor = Color.Red   
NodeButton.Text = (NodeID)

NodeID是程序中其他地方声明的变量

1 个答案:

答案 0 :(得分:1)

First, as already said in the comments you should change Dim NodeButton As New Control to Dim NodeButton As New Button

In second place I believe that you should add the new control to your form using something like this:

Me.Controls.Add(NodeButton)