Link to home
Start Free TrialLog in
Avatar of xtran888
xtran888

asked on

Switching different pen color

I try to switch different pen color for drawing bar chart as shown:

      for ( int i=0; i<= nElements -1 ; i++)
      {

        if ( i %2 )
            {
                  CPen pPen(PS_SOLID, 3, RGB(44,224,228));
                  CPen *pOldPen = pDC->SelectObject (&pPen);
            }
            else
            {
                  CPen pPen(PS_SOLID, 3, RGB(51,204,204));
                  CPen *pOldPen = pDC->SelectObject (&pPen);
            }
            int nY = ConvertY( dPrice[i]);
            int nX = ConvertX( dVolume[i]);

#ifdef _DEBUG
      fprintf(fpt,"i=%d,Price=%f,Y=%d,Volume=%f, X=%d\n", i, dPrice[i],nY,dVolume[i],nX);
#endif
            if ( nX <= LOWLEFT_MARGIN || nY <= HIGHLEFT_MARGIN)
            {
                  nX = LOWLEFT_MARGIN;
                  nY = HIGHLEFT_MARGIN;
            }

            pDC->MoveTo (LOWLEFT_MARGIN, nY);
            pDC->LineTo (nX,nY);
            
      }

But it does not change color while index (i) changes from odd to even number. How can I make the
color change?
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xtran888
xtran888

ASKER

Thanks, it's working fine.