如何让控件重绘Windows窗体?

时间:2014-05-28 11:43:40

标签: c# winforms visual-studio redraw

我不确定"重绘"是我正在寻找的......我是手工设计Windows表单的新手。我创建了一个将使用" TableLayoutPanel"作为传递变量并在该表布局面板中进行自己的设计,以便可以重用控件并调整其参数以适合其包含的数据。

我有一个事件会在调整框架大小时重绘控件,这样可以正常工作。但是,当我第一次。显示()表单时,它不会显示类中的任何子控件。如果我手动调用"调整大小"从Resize事件调用的方法,它也不会重绘自己。

我得到的只是一个空白" TableLayoutPanel"直到我手动调整窗口大小调用"调整大小"父TableLayoutPanel上的事件。

这是我班级的一个被删除的版本,删除了这些方法,因为它们并不真正相关:

    public class DataTableFrame : Form
    {

        TableLayoutPanel MyFrame;
        Size ParentSize;
        int Row = 1;
        int Col = 1;
        int LabelWidth = 75;
        int TextWidth = 150;            
        List<DataObject> MyData = new List<DataObject>();


        public class DataObject
        {...
        }

        public DataTableFrame() { }

        public DataTableFrame(TableLayoutPanel Parent)
        {
            MyFrame = Parent;
            MyFrame.AutoScroll = true;
            ParentSize = MyFrame.Size;
            MyFrame.Layout += new LayoutEventHandler(MyFrame_Layout);
        }

        void MyFrame_Layout(object sender, LayoutEventArgs e)...

        public void AddData(string Label, string Data)...

        public void EvaluateRowCol()...

        public void RowsColums(int Rows, int Cols)...

        public void PopulateControls()...

        public void Refresh()
        {
           // What do I put here to force a redraw???
        }

    }

1 个答案:

答案 0 :(得分:6)

this.Invalidate(); //Refreshes or invoke the control to redraw

this.Refresh();

注意:Refresh()已经在Form对象属性中,您不必声明它。