[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

problem abstracting border drawing

Posted on 2003-10-29
12
Medium Priority
?
343 Views
Last Modified: 2010-04-16
ref. the code below
have a class that draws a border around itself
want a base class that handles the border drawing

:: here the border gets drawn ::

public MyClass
{
     public MyClass()
     {
     }

     protected override void OnResize(EventArgs e)
     {
          this.Invalidate();
     }

     protected override void OnPaint(PaintEventArgs e)
     {
          Graphics g = e.Graphics;

          /* draw shape */

          /* draw border */
     }
}

:: here it never gets drawn ::

public BaseClass
{
     public BaseClass()
     {
          this.Invalidated += new InvalidateEventHandler(this.DrawBorder);
     }

     protected void DrawBorder(object sender, InvalidateEventArgs e)
     {
          Graphics g = Graphics.FromWhnd(this.Handle);

          /* draw border */
     }
}

:: solution ::

that's why I'm here :D
0
Comment
Question by:cuynen
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 9650310
try adding your border drawing  to the paint event
0
 
LVL 2

Author Comment

by:cuynen
ID: 9650641
:: subscribing to the Paint event ::

public BaseClass
{
     public BaseClass()
     {
          this.Paint += new PaintEventHandler(this.DrawBorder);
     }

     protected void DrawBorder(object sender, PaintEventArgs e)
     {
          Graphics g = e.Graphics;

          /* draw border */
     }
}

:: thoughts ::

it doesn't work because I've overridden the protected OnPaint method in the derived class
if I comment out the overridden method, the border is drawn
but of course then my derived class serves no purpose anymore :)
0
 
LVL 11

Accepted Solution

by:
Agarici earned 1000 total points
ID: 9650742
then in the derived class call 'base.OnPaint' before doing any other drawing
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:cuynen
ID: 9650926
so there is no way the base class can auto-draw the border after the derived is finished painting?
0
 
LVL 11

Expert Comment

by:Agarici
ID: 9650954
the 'OnPaint' method in the base class wont get called unless you call 'base.OnPaint'
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9656224
How about this:

public MyClass
{
    public MyClass()
    {
    }

    protected override void OnResize(EventArgs e)
    {
         this.Invalidate();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
         Graphics g = e.Graphics;

         /* draw shape */

        base.OnPaint(e);
    }
}


public BaseClass
{
    public BaseClass()
    {
    }

    protected override void OnPaint(PaintEventArgs e)
    {
         Graphics g = e.Graphics;

         /* draw border */
    }
}
0
 
LVL 2

Author Comment

by:cuynen
ID: 9656268
yes, that's what I had after Agarici's second comment
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9656326
You could use cuynen's variant.
0
 
LVL 3

Expert Comment

by:WiB
ID: 9659071
Any special reason to draw the border in base class?
0
 
LVL 2

Author Comment

by:cuynen
ID: 9659335
so all subclasses will have a border drawn around them
0
 
LVL 2

Author Comment

by:cuynen
ID: 9659336
*** around their visual representation, that is
0
 
LVL 3

Expert Comment

by:WiB
ID: 9660538
The code in comment from  ptmcomp
Date: 10/31/2003 01:03AM PST  
should work perfectly.

 
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question