views:

169

answers:

2

I am working with a WinForm application that was designed by the previous, now unreachable, develeper. In this app farms are embedded in TabControls through some custom code. My question is, Can anyone help to try and explain why there is a custom _Paint() function in each form that is called from the Load event for that form.

This Paint() method is not actually tied to the form outside of the previously stated daisy chaining. What purpose could this serve? In the code below you will notice That I created a Paint() event and moved part of the code there and everything still seems "Peachy."

Can anyone help me to understand this? Is it simply because of the Public declaration on the custom one?

     private void frmWWCModuleHost_Load(object sender, EventArgs e)
    {
        FormPaint();
    }

    public void FormPaint()
    {
        WinFormCustomHandling.ShowFormInContainerControl(tpgCaseNotes, new FrmCaseNotes());
        WinFormCustomHandling.ShowFormInContainerControl(tpgMCP, _frmWWCMCPHost);
        WinFormCustomHandling.ShowFormInContainerControl(tpgMember, _frmWWCMemberHost);
        WinFormCustomHandling.ShowFormInContainerControl(tpgEnrollment, _frmWWCEnrollmentHost);
        WinFormCustomHandling.ShowFormInContainerControl(tpgWWCSearch,_frmWWCSearch);
        WinFormCustomHandling.ShowFormInContainerControl(tpgAudit, FrmAudit);

        // Call each top-Level (visible) tabpage's form FormPaint()
        _frmWWCMCPHost.FormPaint();
    }

    private void FrmModuleHost_Paint(object sender, PaintEventArgs e)
    {
        new psTabRenderer(tclWWCModuleHost, Color.LightSteelBlue, Color.Tomato, Color.Black, Color.Black);
    }
+1  A: 

I'm not sure you posted enough code for it to be understandable. But in general, if you feel the code is unnatural, go ahead and refactor it... one step at the time.

Igor Brejc
Thanks for the comment. I would like to refactor the code but I am afraid I am missing something, hence why I posted; To get "experts" guidance.
Refracted Paladin
+1  A: 

The code looks weird, for sure, but I think you are reading more into the name of the "FormPaint" method than you should. To me, it appears to be just an "initialization" routine, having essentially nothing to do with the Paint event (other than the name).

Also, it appears that any code inside FormPaint is called one time per form, versus any code inside the Paint event handler being called...a lot.

Daniel Pratt
So something I want done once I should leave in the custom Paint() is what you are saying...Thank you!
Refracted Paladin