CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    306

    Drawing Line, then Updating?

    Alright, so if I have a place to draw lines on a form, with a pen and a graphics. How can I keep track of them, so I can update their individual positions if I need to.

    There will be a drawing canvas, as well as a list of the drawn lines, and their points, where you can edit the locations and the lines will update.

    Would an array do it? Or what? Can I even change the individual Xs and Ys of the lines?

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Drawing Line, then Updating?

    Quote Originally Posted by code? View Post
    Alright, so if I have a place to draw lines on a form, with a pen and a graphics. How can I keep track of them, so I can update their individual positions if I need to.

    There will be a drawing canvas, as well as a list of the drawn lines, and their points, where you can edit the locations and the lines will update.

    Would an array do it? Or what? Can I even change the individual Xs and Ys of the lines?
    This depends on what and how it is drawn. If you are drawing simple graphical objects like a circle, a line a rectangle, text, then you can store each item in a list starting every time when the line begins and when it ends.
    for example for a straight line you simple store the start and the endpoint thickness, color and if its a full line, a dotted line...
    All this can be packed into a drawing item class you can design and store them cycle by cycle in a list.
    This way you can undo or redo by simple adding or removing items from the LIFO list (LIFO = Last in First out) maybe google for 'bizdraw' which is a free source code program on codeproject
    It has some errors but basically its easy to be repaired and there you can study how this works
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3
    Join Date
    May 2006
    Posts
    306

    Re: Drawing Line, then Updating?


  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Drawing Line, then Updating?

    Quote Originally Posted by code? View Post
    es OK, but if you want to be able to use Undo then you need to know what was drawn and in which order it was drawn.

    look at this
    http://www.codeproject.com/KB/cs/BizDraw__for_net.aspx

    It does what you expected.
    Basically the point is if you want to change positions of lines and you simple redraw the line to the already drawn screen, then the old line is still visible on screen. If you draw different things one after the other in the same draw event then you can change positions of start and endpoints and redrawing the whole picture and it will be changed. But in both cases you need to store the values of each line with startpoint, endpoint, thickness, color...
    So do a line class and store all whats needed for a single line.
    All changes are done to this class and each single line is an instance of this line class e.g named 'LineData'. You save all of them in a List<LineData>
    If you are drawing you simple run through this list and draw each of the items. Such simple
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

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