如何让控件重绘Windows窗体? [英] How to have a control redraw the Windows form?

查看:183
本文介绍了如何让控件重绘Windows窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm not exactly sure a "redraw" is what I'm looking for... I'm new to designing Windows forms by hand. I've created a class that will use a "TableLayoutPanel" as a passed variable and do its own designing within that table layout panel so the control can be reused and adjust its parameters to fit the data it contains.

我有一个事件,它将在调整框架大小时重新绘制控件,效果很好.但是,当我第一次.Show()表单时,它不会显示该类中的任何子控件.如果我手动调用Resize事件中调用的"resize"方法,它也不会重绘自身.

I have an event that will redraw the control upon resize of the frame, which works fine. However, when I first .Show() the form, it won't show any of the child controls from the class. If I manually invoke the "resize" method which is called from the Resize event it won't redraw itself either.

我得到的只是一个空白的"TableLayoutPanel",直到我手动调整在父TableLayoutPanel上调用"Resize"事件的窗口的大小为止.

All I get is a blank "TableLayoutPanel" until I manually resize the window which invokes the "Resize" event on the parent TableLayoutPanel.

这是我的类的推定版本,其中的方法与实际无关,因此将其删除:

Here's a trunchated version of my class with the methods removed as they're not really relevant:

    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???
        }

    }

推荐答案

尝试

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

this.Refresh();

注意:Refresh()已经在Form对象属性中,您无需声明它.

Note: Refresh() is already in Form object property you don't have to declare it.

这篇关于如何让控件重绘Windows窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆