Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Lines disappear

Lines disappear

Scheduled Pinned Locked Moved C#
graphicshelpquestion
18 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S ssoffline

    Hi i have a made an app where you can draw things like lines graphics etc.,the problem is that when i save it there are no lines in bitmap, though all the physiacal controls like labels are there , but no lines or graphics why?

    Sameer Sood Microsoft Student partner NIT Durgapur,india

    G Offline
    G Offline
    Guffa
    wrote on last edited by
    #2

    How do you keep the information about the graphics, and what do you do to save it?

    --- b { font-weight: normal; }

    S 1 Reply Last reply
    0
    • G Guffa

      How do you keep the information about the graphics, and what do you do to save it?

      --- b { font-weight: normal; }

      S Offline
      S Offline
      ssoffline
      wrote on last edited by
      #3

      Acrually only lines disappear as they are drawn using GDI, i have saved the start and end point of the line in an rraList, the lines are not coming rest evrything is there, they are redrawn on page invalidation,sohelp if any solution out

      Sameer Sood Microsoft Student partner NIT Durgapur,india

      G 1 Reply Last reply
      0
      • S ssoffline

        Acrually only lines disappear as they are drawn using GDI, i have saved the start and end point of the line in an rraList, the lines are not coming rest evrything is there, they are redrawn on page invalidation,sohelp if any solution out

        Sameer Sood Microsoft Student partner NIT Durgapur,india

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #4

        Ok, but what do you do to save it, then?

        --- b { font-weight: normal; }

        S 1 Reply Last reply
        0
        • G Guffa

          Ok, but what do you do to save it, then?

          --- b { font-weight: normal; }

          S Offline
          S Offline
          ssoffline
          wrote on last edited by
          #5

          Bitmap bp = new Bitmap(900, 800); MainPanel.DrawToBitmap (bp,new Rectangle(0,0,900,800)); bp.Save(filename + ".bmp"); Mainpanel is the panel where al work is done and 900*80 is the size

          Sameer Sood Microsoft Student partner NIT Durgapur,india

          G 1 Reply Last reply
          0
          • S ssoffline

            Hi i have a made an app where you can draw things like lines graphics etc.,the problem is that when i save it there are no lines in bitmap, though all the physiacal controls like labels are there , but no lines or graphics why?

            Sameer Sood Microsoft Student partner NIT Durgapur,india

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #6

            ssoffline wrote:

            but no lines or graphics why?

            Because they are not on the bitmap, you must be drawing them on top of the bitmap, direct to the screen. That seems obvious, but beyond that, it's impossible to answer without seeing the code ( and the code you posted doesn't count, it doesn't show how/where the lines are being drawn )

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            S 1 Reply Last reply
            0
            • C Christian Graus

              ssoffline wrote:

              but no lines or graphics why?

              Because they are not on the bitmap, you must be drawing them on top of the bitmap, direct to the screen. That seems obvious, but beyond that, it's impossible to answer without seeing the code ( and the code you posted doesn't count, it doesn't show how/where the lines are being drawn )

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              S Offline
              S Offline
              ssoffline
              wrote on last edited by
              #7

              Point ps = new Point(l1.Source.X - 110, l1.Source.Y - 50); Point pd = new Point(l1.Destination.X - 110, l1.Destination.Y - 50); Graphics graph = this.MainPanel.CreateGraphics(); Pen penCurrent = new Pen(Color.Red,4); penCurrent.EndCap = LineCap.ArrowAnchor; graph.DrawLine(penCurrent, ps, pd); penCurrent.Dispose(); This is the code for line drawing, these are drawn no a panel which is located at 110,50 hence the adjustments, or u mean to save here that i should save the form, i tried saving the whole form but then also i have no lines

              Sameer Sood Microsoft Student partner NIT Durgapur,india

              C 1 Reply Last reply
              0
              • S ssoffline

                Point ps = new Point(l1.Source.X - 110, l1.Source.Y - 50); Point pd = new Point(l1.Destination.X - 110, l1.Destination.Y - 50); Graphics graph = this.MainPanel.CreateGraphics(); Pen penCurrent = new Pen(Color.Red,4); penCurrent.EndCap = LineCap.ArrowAnchor; graph.DrawLine(penCurrent, ps, pd); penCurrent.Dispose(); This is the code for line drawing, these are drawn no a panel which is located at 110,50 hence the adjustments, or u mean to save here that i should save the form, i tried saving the whole form but then also i have no lines

                Sameer Sood Microsoft Student partner NIT Durgapur,india

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #8

                ssoffline wrote:

                these are drawn no a panel which is located at 110,50

                OK, why are you using a Panel ? Surely you should be creating a bitmap in memory, drawing it in your paint method, and drawing onto that bitmap. If you're not drawing onto a Bitmap, how are you hoping to save it ?

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                S 1 Reply Last reply
                0
                • S ssoffline

                  Hi i have a made an app where you can draw things like lines graphics etc.,the problem is that when i save it there are no lines in bitmap, though all the physiacal controls like labels are there , but no lines or graphics why?

                  Sameer Sood Microsoft Student partner NIT Durgapur,india

                  S Offline
                  S Offline
                  sam
                  wrote on last edited by
                  #9

                  actually when you move window or minimize/maximize it all the controls redrwan but since you have written your code in some function that doesn't get refresh.Do one thing put that code in in OnPaint() method of your form.you'll be able to show your alll the time :) sameer

                  S 1 Reply Last reply
                  0
                  • S sam

                    actually when you move window or minimize/maximize it all the controls redrwan but since you have written your code in some function that doesn't get refresh.Do one thing put that code in in OnPaint() method of your form.you'll be able to show your alll the time :) sameer

                    S Offline
                    S Offline
                    ssoffline
                    wrote on last edited by
                    #10

                    @sameer i am doing that in onpaint event only and they don't diappear in maximize minimize

                    Sameer Sood Microsoft Student partner NIT Durgapur,india

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      ssoffline wrote:

                      these are drawn no a panel which is located at 110,50

                      OK, why are you using a Panel ? Surely you should be creating a bitmap in memory, drawing it in your paint method, and drawing onto that bitmap. If you're not drawing onto a Bitmap, how are you hoping to save it ?

                      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                      S Offline
                      S Offline
                      ssoffline
                      wrote on last edited by
                      #11

                      i am using a panel because my app is used for making diagrams, so al objects other than lines are user controls, and secondly how to do that in memory,Do you mean that i shoul draw lines manually on the bitmap i am gonna save?

                      Sameer Sood Microsoft Student partner NIT Durgapur,india

                      C 1 Reply Last reply
                      0
                      • S ssoffline

                        i am using a panel because my app is used for making diagrams, so al objects other than lines are user controls, and secondly how to do that in memory,Do you mean that i shoul draw lines manually on the bitmap i am gonna save?

                        Sameer Sood Microsoft Student partner NIT Durgapur,india

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #12

                        ssoffline wrote:

                        so al objects other than lines are user controls

                        No, they should be different classes with a common base class, which are used to draw the objects on your main control.

                        ssoffline wrote:

                        Do you mean that i shoul draw lines manually on the bitmap i am gonna save?

                        Yes, obviously. If you don't draw lines on the bitmap, when you save the bitmap, they aren't going to be there, are they ?

                        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                        S 1 Reply Last reply
                        0
                        • C Christian Graus

                          ssoffline wrote:

                          so al objects other than lines are user controls

                          No, they should be different classes with a common base class, which are used to draw the objects on your main control.

                          ssoffline wrote:

                          Do you mean that i shoul draw lines manually on the bitmap i am gonna save?

                          Yes, obviously. If you don't draw lines on the bitmap, when you save the bitmap, they aren't going to be there, are they ?

                          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                          S Offline
                          S Offline
                          ssoffline
                          wrote on last edited by
                          #13

                          ok thanks i 'll try and tell also i posted earlier today how to make lines resizable? i mean i should be able to select them like controls and resize with mouse? i can move them but how to resize?

                          Sameer Sood Microsoft Student partner NIT Durgapur,india

                          C 1 Reply Last reply
                          0
                          • S ssoffline

                            Bitmap bp = new Bitmap(900, 800); MainPanel.DrawToBitmap (bp,new Rectangle(0,0,900,800)); bp.Save(filename + ".bmp"); Mainpanel is the panel where al work is done and 900*80 is the size

                            Sameer Sood Microsoft Student partner NIT Durgapur,india

                            G Offline
                            G Offline
                            Guffa
                            wrote on last edited by
                            #14

                            If you would have used the Paint event to draw the lines, as I told you in the previous thread, the lines would have been drawn to the bitmap. As you say that they aren't, you can't be doing that. I don't mean to sound harsh, but if you don't follow advice, what would be the point of giving any further advice?

                            --- b { font-weight: normal; }

                            S 1 Reply Last reply
                            0
                            • S ssoffline

                              ok thanks i 'll try and tell also i posted earlier today how to make lines resizable? i mean i should be able to select them like controls and resize with mouse? i can move them but how to resize?

                              Sameer Sood Microsoft Student partner NIT Durgapur,india

                              C Offline
                              C Offline
                              Christian Graus
                              wrote on last edited by
                              #15

                              ssoffline wrote:

                              i mean i should be able to select them like controls and resize with mouse?

                              The way to do this is to create a struct that defines each item. Then keep them in a list, and render them from that list. when the user clicks, you iterate over the list and see if an item was selected. If so, you change the attributes of that object in the list when the user drags or whatever.

                              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                              S 1 Reply Last reply
                              0
                              • G Guffa

                                If you would have used the Paint event to draw the lines, as I told you in the previous thread, the lines would have been drawn to the bitmap. As you say that they aren't, you can't be doing that. I don't mean to sound harsh, but if you don't follow advice, what would be the point of giving any further advice?

                                --- b { font-weight: normal; }

                                S Offline
                                S Offline
                                ssoffline
                                wrote on last edited by
                                #16

                                hi I am doing it in OnPaint event and i even redraw them on invalidation, the problem has been solved by christian's suggestion,actually the lines are drawn on screen pixels and objects lie on the panel, so you need to make a bitmap in memory and draw those line son to the bitmap and save it thanks and regards

                                Sameer Sood Microsoft Student partner NIT Durgapur,india

                                G 1 Reply Last reply
                                0
                                • C Christian Graus

                                  ssoffline wrote:

                                  i mean i should be able to select them like controls and resize with mouse?

                                  The way to do this is to create a struct that defines each item. Then keep them in a list, and render them from that list. when the user clicks, you iterate over the list and see if an item was selected. If so, you change the attributes of that object in the list when the user drags or whatever.

                                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                                  S Offline
                                  S Offline
                                  ssoffline
                                  wrote on last edited by
                                  #17

                                  hi thanks for previous suggestions, i am already doing the same only, in fact i can save and compile my diagram and even reopen it using XML, my problem is how to show those selected points as are shown in windows form editor around that graphics object, of course if it becomes selectable like other controls then resizing is no big thing.

                                  Sameer Sood Microsoft Student partner NIT Durgapur,india

                                  1 Reply Last reply
                                  0
                                  • S ssoffline

                                    hi I am doing it in OnPaint event and i even redraw them on invalidation, the problem has been solved by christian's suggestion,actually the lines are drawn on screen pixels and objects lie on the panel, so you need to make a bitmap in memory and draw those line son to the bitmap and save it thanks and regards

                                    Sameer Sood Microsoft Student partner NIT Durgapur,india

                                    G Offline
                                    G Offline
                                    Guffa
                                    wrote on last edited by
                                    #18

                                    What control's paint event is it that you use, then? Are you using the graphics object that is supplied to you in the event attributes, or are you creating a completely new graphics object? If you don't use the graphics object that is supplied, you will always be drawing to the screen, even when the DrawToBitmap is trying to make you draw to the bitmap. If you do it correctly, there is no need to draw the lines to the bitmap separately.

                                    --- b { font-weight: normal; }

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups