Display text is delayed

Jun 6 2006 10:43 PM
I have a treeview which lists all the chapters of a book. Whenever the treeView is selected, the program is supposed to paint the text of the entire chapter onto a tabpage. ******************************************************************************* private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { // a query is run here to produce a result of text from a certain chapter and then import it to a chap_lines string array tabPage1.Paint += new PaintEventHandler(tabPage1_Paint); } private void tabPage1_Paint(object sender, PaintEventArgs e) { y = 8; Graphics g = e.Graphics; foreach (string line in chap_lines) { g.DrawString(line, new Font("Courier New", 10, System.Drawing.FontStyle.Regular), new SolidBrush(Color.Black), 3, y); y = y+20; } } ******************************************************************************* The problem is that the text is not painted until the next chapter node is selected. Chapter 1 is okay as it is the default node. But if I then select chapter 3, those text of chapter 1 stay there. The text of chapter 3 is not displayed until another chapter is selected. The thing is when I debug the program setting the breakpoint at "tabPage1.Paint += new PaintEventHandler(tabPage1_Paint)", it gives me the correct result. But if I set the breakpoint anywhere in the tabPage1_Paint event, it can never get out of itself. Why is that? How can I display its correct text once a chapter is selected? Also, I have set the tabPage1.AutoScroll to true but it still doesn't scroll to display those lines that are not visible to the tabPage1 area.