CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2005
    Posts
    55

    Question 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?

  2. #2
    Join Date
    Sep 1999
    Posts
    137

    Re: Click a button and change color on rectangle?

    if(fargered=true)
    Perhaps this should be
    if(fargered==true)

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: 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:
    So what is the problem? Should we guess?

    Code:
    if(fargered=true)
    Perhaps this should be
    Code:
    if(fargered==true)
    You should not use any of the two forms, but:
    Code:
    if(fargered)
    and if you want to test it agains false then
    Code:
    if(!fargered)
    PS: doesn't you compiler give you a warning here
    Code:
    if(fargered=true)
    It should.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Apr 2005
    Posts
    55

    Re: Click a button and change color on rectangle?

    No warning from the compiler, strange since you said that.

    I'll check...

  5. #5
    Join Date
    May 2005
    Posts
    70

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured