Hello guys, Ive been working this for 2 days, I am required to position a string using drawstring but the problem is its dynamic and changes depending on the database or source. A quick fix I thought was to position it at the end of the report but its required at the middle of other entries. Can you give me tips and different approach how to programmaticall y adjust the height of the rectangle depending on the string it would need to write?
here's my approach:
i used a data structure approach like of an stack but not literally a pushes and pops.
i measured how many pixels it would take for a single line of string could be possible. and its 15. I made a method that returns how many lines (which is 15 pixels per line) it is possible for the string that you will pass as a parameter. if the string is all upper its possible to limit each line with a fixed number of characters posible by giving the constant of the rectangle's length. But the problem that I encounter is that it has special characters and spaces which mean it will adjust to the next line if it is not possible for it the write it from the previous line. If the string is too long again for the next line it would randomly concatenate it self to the next. I made again a method but what keeps me scratching my head is beacause there will be always no fix number of characters per line. im coding in c#. im also using devexpress xtraprinting library,
<start of code snippet>
float line=GetLine(ch ecknull,31) // string input then supposedly number of characters.
rec = new RectangleF(230, y, 208, (float)(line * 13));
e.Graph.DrawStr ing(/*tempstring*/checknull, Color.Black, rec, DevExpress.Xtra Printing.Border Side.None);
private float GetLine(string tempstring, int size)
{
int ctr = 0;
int line = 0;
int posnext = 0;
int pos = 0;
bool space = false;
int word = 0;
bool cutoff = false;
float retline = 0;
CharEnumerator charEnum = tempstring.GetE numerator();
while (charEnum.MoveN ext())
{
if (Convert.ToInt3 2(tempstring[ctr]) == 32)
{
space = true;
pos++;
posnext++;
word++;
}
else
{
space = false;
pos++;
posnext++;
word++;
}
if (posnext == size)
{
cutoff = true;
pos = word;
posnext = 0;
}
if (space == true && pos < size && cutoff==false )
{
line += word;
word = 0;
}
if (space == true && cutoff == true)
{
if (word > size)
{
while (word > size)
{
word-=size;
retline++;
}
line += word;
if (line > size)
{
pos = line - size;
retline++;
line = pos;
word = 0;
}
cutoff = false;
}
else
{
retline++;
line = pos;
word = 0;
cutoff = false;
}
posnext = pos;
}
ctr++;
}
if (line < size)
{
retline += 2;
}
retline+=1;
return retline;
}
<end of code snippet>
here is a sample string input:
1) MAX(PC!.ADVISED AMT, PC!.DETAMT)
2) IF(PC!.ADCBCGRA DETP="BCGRADESC LEANING",IF(ISE RROR(VLOOKUP(PC !.ADCPOSI,PT.BC GRADESCLEANING, 2,FALSE)),"",VL OOKUP(PC!.ADCPO SI,PT.BCGRADESC LEANING,2,FALSE )),IF(PC!.ADCBC GRADETP="BCGRAD ESELECTRICAL",I F(ISERROR(VLOOK UP(PC!.ADCPOSI, PT.BCGRADESELEC TRICAL,2,FALSE) ),"",VLOOKUP(PC !.ADCPOSI,PT.BC GRADESELECTRICA L,2,FALSE)), IF(PC!.ADCBCGRA DETP="BCGRADESM EIBC",IF( ISERROR(VLOOKUP (PC!.ADCPOSI, PT.BCGRADESMEIB C,2,FALSE)),"", VLOOKUP(PC!.ADC POSI,PT.BCGRADE SMEIBC,2,FALSE) ),IF(PC!.ADCBCG RADETP="BCGRADE SMIBCO",IF( ISERROR(VLOOKUP (PC!.ADCPOSI, PT.BCGRADESMIBC O,2,FALSE)),"", VLOOKUP(PC!.ADC POSI,PT.BCGRADE SMIBCO,2,FALSE) ),IF(PC!.ADCBCG RADETP= "BCGRADESNRFBC" ,IF( ISERROR(VLOOKUP (PC!.ADCPOSI, PT.BCGRADESNRFB C,2,FALSE)), "", VLOOKUP(PC!.ADC POSI,PT.BCGRADE SNRFBC,2,FALSE) ),"")))))
found this article here and scans it: http://www.thescripts.com/forum/thread262845.html
First time to post on this forum. I'll reply as soon as posible tnx
thanks sorry for my english. using xp. any suggetions?
here's my approach:
i used a data structure approach like of an stack but not literally a pushes and pops.
i measured how many pixels it would take for a single line of string could be possible. and its 15. I made a method that returns how many lines (which is 15 pixels per line) it is possible for the string that you will pass as a parameter. if the string is all upper its possible to limit each line with a fixed number of characters posible by giving the constant of the rectangle's length. But the problem that I encounter is that it has special characters and spaces which mean it will adjust to the next line if it is not possible for it the write it from the previous line. If the string is too long again for the next line it would randomly concatenate it self to the next. I made again a method but what keeps me scratching my head is beacause there will be always no fix number of characters per line. im coding in c#. im also using devexpress xtraprinting library,
<start of code snippet>
float line=GetLine(ch ecknull,31) // string input then supposedly number of characters.
rec = new RectangleF(230, y, 208, (float)(line * 13));
e.Graph.DrawStr ing(/*tempstring*/checknull, Color.Black, rec, DevExpress.Xtra Printing.Border Side.None);
private float GetLine(string tempstring, int size)
{
int ctr = 0;
int line = 0;
int posnext = 0;
int pos = 0;
bool space = false;
int word = 0;
bool cutoff = false;
float retline = 0;
CharEnumerator charEnum = tempstring.GetE numerator();
while (charEnum.MoveN ext())
{
if (Convert.ToInt3 2(tempstring[ctr]) == 32)
{
space = true;
pos++;
posnext++;
word++;
}
else
{
space = false;
pos++;
posnext++;
word++;
}
if (posnext == size)
{
cutoff = true;
pos = word;
posnext = 0;
}
if (space == true && pos < size && cutoff==false )
{
line += word;
word = 0;
}
if (space == true && cutoff == true)
{
if (word > size)
{
while (word > size)
{
word-=size;
retline++;
}
line += word;
if (line > size)
{
pos = line - size;
retline++;
line = pos;
word = 0;
}
cutoff = false;
}
else
{
retline++;
line = pos;
word = 0;
cutoff = false;
}
posnext = pos;
}
ctr++;
}
if (line < size)
{
retline += 2;
}
retline+=1;
return retline;
}
<end of code snippet>
here is a sample string input:
1) MAX(PC!.ADVISED AMT, PC!.DETAMT)
2) IF(PC!.ADCBCGRA DETP="BCGRADESC LEANING",IF(ISE RROR(VLOOKUP(PC !.ADCPOSI,PT.BC GRADESCLEANING, 2,FALSE)),"",VL OOKUP(PC!.ADCPO SI,PT.BCGRADESC LEANING,2,FALSE )),IF(PC!.ADCBC GRADETP="BCGRAD ESELECTRICAL",I F(ISERROR(VLOOK UP(PC!.ADCPOSI, PT.BCGRADESELEC TRICAL,2,FALSE) ),"",VLOOKUP(PC !.ADCPOSI,PT.BC GRADESELECTRICA L,2,FALSE)), IF(PC!.ADCBCGRA DETP="BCGRADESM EIBC",IF( ISERROR(VLOOKUP (PC!.ADCPOSI, PT.BCGRADESMEIB C,2,FALSE)),"", VLOOKUP(PC!.ADC POSI,PT.BCGRADE SMEIBC,2,FALSE) ),IF(PC!.ADCBCG RADETP="BCGRADE SMIBCO",IF( ISERROR(VLOOKUP (PC!.ADCPOSI, PT.BCGRADESMIBC O,2,FALSE)),"", VLOOKUP(PC!.ADC POSI,PT.BCGRADE SMIBCO,2,FALSE) ),IF(PC!.ADCBCG RADETP= "BCGRADESNRFBC" ,IF( ISERROR(VLOOKUP (PC!.ADCPOSI, PT.BCGRADESNRFB C,2,FALSE)), "", VLOOKUP(PC!.ADC POSI,PT.BCGRADE SNRFBC,2,FALSE) ),"")))))
found this article here and scans it: http://www.thescripts.com/forum/thread262845.html
First time to post on this forum. I'll reply as soon as posible tnx
thanks sorry for my english. using xp. any suggetions?
Comment