drawing lines in windows forms application.

I use Visual VC++ Express Edition.it seems that it doesn`t have MFC.so i used windows form application instead.i was going to create a form,put some bottoms on it and  by clicking on the bottoms some lines and rectangle (that are used in drawing flowcharts) appear in the form in different positions.i create a class  (with class wizard)and wrote codes for drawing this lines...i used  these functions:

CClienttDC dc(this);

Cpen *pen1=dc.SelectStockObject(WHITE_PEN);

dc.lineto(50,50);

AND these are error messeges:

.\shekl.cpp(14) : error C2065: 'CClientDC' : undeclared identifier

.\shekl.cpp(14) : error C2146: syntax error : missing ';' before identifier 'dc'

.\shekl.cpp(14) : error C3861: 'dc': identifier not found

.\shekl.cpp(15) : error C2065: 'Cpen' : undeclared identifier

.\shekl.cpp(15) : error C2065: 'pen1' : undeclared identifier

.\shekl.cpp(15) : error C2228: left of '.SelectStockObject' must have class/struct/union

type is ''unknown-type''

.\shekl.cpp(15) : error C2065: 'WHITE_PEN' : undeclared identifier

.\shekl.cpp(16) : error C2228: left of '.lineto' must have class/struct/union

PLEASE HEEEEELP



Answer this question

drawing lines in windows forms application.

  • abstar

    In the .NET (non MFC) world we’ve got the rather easy to use System.Drawing namespace which makes drawing to the screen quite easy... unfortunately for the life of me I cannot find a decent Managed C++ tutorial on it.

    I would suggest taking a read of this excellent one (which sadly for you is in C#) and then once you’ve come to understand what is possible, take a look at this Managed C++ one or this one, sadly they don't go as in depth as the first, but will still get you going in C++.



  • StatlerW

    Did you read any of the tutorials linked to by Brendan Grant They explain rather well how to draw a rectangle in the event handler for the Paint event.

    The simplest way would be to change some state of your object so that it knows to draw a rectangle in its paint event handler in your click event handler followed by a call to Control.Invalidate to force the control to redraw. In the paint event handler you check if you should draw a rectangle, and if you should you draw it using for example Graphics.DrawRectangle.

  • Garyrg9

    Can someone bring some example codes.i currently have built a form,and I put some bottoms on it,i want that when I click on the bottom a rectangle be drawn on the form.i know i should use an event but I don`t know which codes i should type in form.h.

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    //what should I type here to draw a rectangle

    }

    please someone help me, I`m in a really bad situation


  • Slim

    To draw on a .NET control you normally add an event handler for its Paint event and do your painting in the event handler using the Graphics object you get from the event arguments.


  • drawing lines in windows forms application.