GDI+ text problem

carolpanda

New Member
I want to print some text in a GDI+ image. That works just fine.<BR><BR>But the problem is that I use a loop to read the strings. The image is generated and my text is overlapping. It mixes with the other lines that i drawed. <BR>I want to break off the text string after every word and put a break between them.<BR><BR>Here's my code so far:<BR><BR>Const iColWidth As Integer = 30<BR> Const iColSpace As Integer = 30<BR> Const iMaxHeight As Integer = 100<BR> Const iHeightSpace As Integer = 25<BR> Const iXLegendSpace As Integer = 12<BR> Const iTitleSpace As Integer = 50<BR><BR> Dim iMaxWidth As Integer = (iColWidth + iColSpace) * aX.Count + iColSpace<BR> Dim iMaxColHeight As Integer = 0<BR> Dim iTotalHeight As Integer = iMaxHeight + iXLegendSpace + iTitleSpace<BR><BR> Dim objBitmap As Bitmap = New Bitmap(iMaxWidth, iTotalHeight)<BR> Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)<BR><BR> objGraphics.FillRectangle(New SolidBrush(Color.White), 0, 0, iMaxWidth, iTotalHeight)<BR> objGraphics.FillRectangle(New SolidBrush(Color.White), 0, 0, iMaxWidth, iMaxHeight)<BR><BR> ' find the maximum value<BR> Dim iValue As Integer<BR> For Each iValue In aY<BR> If iValue > iMaxColHeight Then iMaxColHeight = iValue<BR> Next<BR><BR> Dim iBarX As Integer = iColSpace, iCurrentHeight As Integer<BR> Dim objBrush As SolidBrush = New SolidBrush(Color.Red)<BR> Dim fontLegend As Font = New Font("Arial", 8)<BR> Dim fontValues As Font = New Font("Arial", 8)<BR> Dim fontTitle As Font = New Font("Arial", 12)<BR><BR> ' loop through and draw each bar<BR> Dim iLoop As Integer<BR> For iLoop = 0 To aX.Count - 1<BR> iCurrentHeight = (Convert.ToDouble(aY(iLoop)) / Convert.ToDouble(iMaxColHeight)) * Convert.ToDouble(iMaxHeight - iHeightSpace)<BR><BR> objGraphics.FillRectangle(objBrush, iBarX, iMaxHeight - iCurrentHeight, iColWidth, iCurrentHeight)<BR> objGraphics.DrawString(aX(iLoop), fontLegend, objBrush, iBarX, iMaxHeight)<BR> objGraphics.DrawString(String.Format("{0:#,###}", aY(iLoop)), fontValues, objBrush, iBarX, iMaxHeight - iCurrentHeight - 15)<BR><BR> iBarX += (iColSpace + iColWidth)<BR> Next<BR><BR> Dim salign As New System.Drawing.StringFormat()<BR><BR> salign.Alignment = StringAlignment.Center<BR> objGraphics.DrawString(strTitle, fontTitle, objBrush, (iMaxWidth / 2) - strTitle.Length * 4, iMaxHeight + iXLegendSpace)<BR> salign.Alignment = StringAlignment.Center<BR><BR> objBitmap.Save(Target, ImageFormat.Gif)<BR> objGraphics.Dispose()<BR> objBitmap.Dispose()<BR><BR><BR>I hope someone can help me
 
Back
Top