I cannot for the life of me get a custom control updating itself. In the below example, "test label1" works and outputs as expected. However when I try and get it to do the same thing later on, it will not. I've tried calling Update and Invalidate, but still nothing. Am I missing something?
Swapping the points around doesn't work either, so it doesn't look like it's just off screen for example.
public partial class AdvancedListControl : UserControl
{
public void createAnotherLabel()
{
Controls.Add(new Label { Location = new Point(14, 14), AutoSize = true, Text = "test label2 - test" }); // this won't create
// me.Controls.Add(new Label { Location = new Point(14, 14), AutoSize = true, Text = "test label2 - test" });
// Update();
// Invalidate();
}
private AdvancedListControl me;
public AdvancedListControl()
{
InitializeComponent();
me = this;
Controls.Add(new Label { Location = new Point(26, 26), AutoSize = true, Text = "test label1" });
}
}
Thanks.
该控制方法必须由最终用户操作(如按钮的事件处理程序)驱动的控件调用,从而导致页面回发,这将导致该控件触发该方法并以更新控件状态呈现页面。
Meh! Noob mistake. I did the same as Jashaszun and created a new project, and yes it did work. Turns out I had two copies of the advanced control on a form, and the one that was hiding was the one I was hitting. It's been a long day. ;-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.