C# String Concatenation OutOfRange error -
i'm utilizing string functions "label" class put lines print on bitmap. program compiles fine, , previous form passes labelqueue (it appear no issue before tried print bitmap). code of particular initializer/constructor below. erroneous lines of code final 3 lines of function before "c++".
let me know if need me add more necessary code.
i'm getting indexoutofrange exception, claiming outside of bounds of array.
private labelqueue lq; public print(labelqueue queue) { initializecomponent(); lq = queue; picturebox1.image = new bitmap(2550, 3300); system.drawing.graphics formgraphics = this.creategraphics(); system.drawing.font textfont = new system.drawing.font("times new roman", 8); system.drawing.solidbrush textbrush = new system.drawing.solidbrush(system.drawing.color.black); system.drawing.stringformat textformat = new system.drawing.stringformat(); int x, y, c = 0; while (c < 30) { // coordinates put values. x = ((c % 3) * 600) + 300; // accounts column gap if (c % 3 > 0) x = x + ((c % 3) - 1) * 75; y = ((c % 10) * 270) + 300; string firstline, secondline, thirdline; firstline = lq.labels[c].getlastname() + ", " + lq.labels[c].getfirstname() + " " + lq.labels[c].getmiddlename(); secondline = lq.labels[c].getnewstreet(); thirdline = lq.labels[c].getnewcity() + ", " + lq.labels[c].getnewstate() + lq.labels[c].getnewzip() + lq.labels[c].getnewcountry(); formgraphics.drawstring(firstline, textfont, textbrush, x, y, textformat); // line turning error formgraphics.drawstring(firstline, textfont, textbrush, x, y + 10, textformat); // naturally, both these lines need fixed formgraphics.drawstring(firstline, textfont, textbrush, x, y + 20, textformat); c++; } }
without a good, minimal, complete code example reliably demonstrates problem, it's impossible know sure exact fix need.
however, based on information on question , comments far, appears aren't limiting loop correctly. while
statement should this:
while (c < lq.count())
note above uses enumerable.count()
extension method. chose answer, because didn't include declaration/implementation of labelqueue
object, there's no way know sure correct syntax be, extension method work because pretty reasonable collection type supports indexer implement some interface allows enumerable.count()
method work well.
that said, type probably has count
property, can use instead of count()
extension method. either work equally well.
finally, future reference fine answer own question. it's answer should be answer. i.e. needs explain wrong, , did fix it. writing "issue fixed" doesn't count answer.
for matter, if don't answer here , want write own, can still that. can accept own answer instead of mine if you'd rather. make sure it's real answer.
Comments
Post a Comment