Click a button and change color on rectangle?
I have a problem. I need to change color to the rectangle when I click a button on the toolbar.
Here is the code for OnDraw:
Code:
void CObligatorisk_oppgaveView::OnDraw(CDC* pDC){
CObligatorisk_oppgaveDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// Tegner ut rektangel A og rektangel B og resultatet C
pDC->FrameRect(rectA, &blackBrush);
pDC->FrameRect(rectB, &blackBrush);
if(fargered=true)
{
pDC->FrameRect(rectC, &redBrush);
}
else
{
CBrush blackHatchBrush;
blackHatchBrush.CreateHatchBrush(HS_FDIAGONAL, RGB(0,0,0));
CBrush* pOldBrush = pDC->SelectObject(&blackHatchBrush);
CPen blackPen;
blackPen.CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&blackPen);
pDC->Rectangle(rectC);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
Here is the code for the button:
Code:
void CObligatorisk_oppgaveView::OnFargerR()
{
fargered = true;
Invalidate();
}
Can some one help me? :wave:
Re: Click a button and change color on rectangle?
Perhaps this should be
Quote:
if(fargered==true)
Re: Click a button and change color on rectangle?
Quote:
I have a problem. I need to change color to the rectangle when I click a button on the toolbar.
Here is the code for OnDraw:
So what is the problem? :confused: Should we guess?
You should not use any of the two forms, but:
and if you want to test it agains false then
PS: doesn't you compiler give you a warning here
It should.
Re: Click a button and change color on rectangle?
No warning from the compiler, strange since you said that.
I'll check...
Re: Click a button and change color on rectangle?
The compiler generates a warning on an assignment within conditional expression on Warning Level 4, looks like you didn't change the default level 3.