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???
}
}
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With