Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a control redraw the Windows form?

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.

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.

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

    }
like image 895
ThisHandleNotInUse Avatar asked May 28 '14 11:05

ThisHandleNotInUse


People also ask

How do I control a selection window?

Hold down the "Ctrl" key and the "Shift" key. Press the right arrow key to select the word to the right, or press the left arrow key to select the word to the left. Select one character at a time by holding down the "Shift" key and and using either arrow key (right or left).


1 Answers

try

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

or

this.Refresh();

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

like image 193
Jade Avatar answered Sep 27 '22 17:09

Jade