0

I am using C# to write data to a print page, and the data is outputting in the incorrect order. I need to change the order so that it will display as 1, 4, 2, 3 and not in 1, 2, 3, 4

This is my current syntax:

//Section 1
int iAreaStartLX = iLegendsBoxX + 8;
int iAreaStartLY = iLegendsBoxY + 8;
int iTextXPos = iAreaStartLX + 50;
int iTriStartLX = iAreaStartLX + 25;
Point[] AreaStartPts = new Point[3];
AreaStartPts[0] = new Point(iTriStartLX, iAreaStartLY);
AreaStartPts[1] = new Point(iTriStartLX + 20, iAreaStartLY);
AreaStartPts[2] = new Point(iTriStartLX + 10, iAreaStartLY + 18);
e.Graphics.FillPolygon(StartSahpeBrush, AreaStartPts);
e.Graphics.DrawPolygon(Pens.Red, AreaStartPts);
e.Graphics.DrawString("Data For Point 1", new Font("Times New Roman", 10), new SolidBrush(Color.Black), iTextXPos, 105);

//Section 2
int iLNStartLX = iAreaStartLX;
int iLNStartLY = iAreaStartLY + 25;
Point point1 = new Point(iLNStartLX, iLNStartLY + 10);
Point point2 = new Point(iLNStartLX + 45, iLNStartLY + 10);
e.Graphics.DrawLine(RedDashPen, point1, point2);
e.Graphics.DrawString("Data For Point 2", new Font("Times New Roman", 10), new SolidBrush(Color.Black), iTextXPos, 130);

//Section 3
int iLNEndLX = iAreaStartLX;
int iLNEndLY = iLNStartLY + 25;
point1 = new Point(iLNEndLX, iLNEndLY + 10);
point2 = new Point(iLNEndLX + 45, iLNEndLY + 10);
e.Graphics.DrawLine(RedPen, point1, point2);
e.Graphics.DrawString("Data For Point 3", new Font("Times New Roman", 10), new SolidBrush(Color.Black), iTextXPos, 155);

//Section 4
int iAreaEndLY = iLegendsBoxY + 85;
int iTextYPos = iAreaStartLX + 50;
int iTriEndLX = iAreaStartLX + 25;
AreaStartPts[0] = new Point(iTriEndLX, iAreaEndLY);
AreaStartPts[1] = new Point(iTriEndLX + 20, iAreaEndLY);
AreaStartPts[2] = new Point(iTriEndLX + 10, iAreaEndLY + 18);
e.Graphics.DrawPolygon(RedDottedPen, AreaStartPts);
e.Graphics.DrawString("Data For Point 4", new Font("Times New Roman", 10), new SolidBrush(Color.Black), iTextXPos, 180);

Now of course I did the obvious and copy/pasted //Section 4 directly under //Section 1 but the output was in the same order. What would be the proper way to change the order these .DrawString display on the page?

  • When you say "order" do you mean in the Y axis (i.e. vertically on the page)? If so, then reordering the code will have no effect. You clearly need to change the Y coordinates for all of the section 4 parts. – Jonathon Reinhart Nov 28 '17 at 16:14
  • I got lost in your maze of different variables doing the same thing. I'm guessing you did, too. – LarsTech Nov 28 '17 at 16:19
  • @JonathonReinhart - yes, I am wanting to change the Vertical Position! I am lost tho on how to achieve such.... – BellHopByDayAmetuerCoderByNigh Nov 28 '17 at 16:34
  • 1
    Rather than pasting this thing over and over, write a method that draws one good line, at whatever Y coordinate is passed in, then call it 4 times with a different y coordinate - forget all this "i'll get the Y for this one by adding 25 to the Y from the start of end end of the sum of 25 added onto the last one, or was it the first one." – Caius Jard Nov 28 '17 at 16:38
  • @CaiusJard -> isn't that essentially what I am doing? – BellHopByDayAmetuerCoderByNigh Nov 28 '17 at 16:47
  • 3
    Heck no; consider us like you're leaving your job and we're the developers coming in to replace you and have to maintain your code. None of us *wants* to work out your code, and (6 months down the line from when you wrote your code) you can't work out what it's doing either -> it points to a serious problem with the code -> it's a bit of a dog's dinner.. I'm recommending you clean it up by making a single method like `DrawBox(int yCoord, Pen borderStyle, string textToDisplay)` and then call it like `DrawBox(0, DottedBlackPen, "You owe £20"); DrawBox(50, SolidRedPen, "Pay today or else!");` – Caius Jard Nov 28 '17 at 16:53
  • @CaiusJard -> that is essentially what happened. Original dev quit, and we are trying to decipher the code. I thought it would be easier for a more advanced coder to decipher it (or point in the proper direction) - however it seems that as you suggested - creating a method to achieve desired results will be best – BellHopByDayAmetuerCoderByNigh Nov 28 '17 at 16:58
  • You might find some mileage then, in renaming the variables in VS (so it renames all occurrences of the variable). A lot of the names are confusingly similar enough that it's just not clear what they're for.. In other areas, we call this obfuscation :) - unobfuscating is the process of taking `iTriEndLX` and renaming it to `chartAreaLeftEdgeX` or something similarly readable, so that when you see `chartAreaLeftEdgeX + 20` you can say "oh, that's 20 pixels in from the left edge of the chart box". Using a pen and paper to sketch out coords will also help. – Caius Jard Nov 28 '17 at 17:14
  • Remember in graphics that an increasing value of Y is actually going down the page. The origin 0,0 is in the top left corner – Caius Jard Nov 28 '17 at 17:17

0 Answers0