-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportTools.cs
478 lines (421 loc) · 24.1 KB
/
ReportTools.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
//=============================================================
// ReportTools
//-------------------------------------------------------------
// 09/11/15 17.0.90.12/5.200.12 DrawTextBox_AlignCenter
// 09/22/14 17.0.39.0/5.150.2 Print_LetterHead added
//=============================================================
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace KoWordSearch
{
public class ReportTools
{
private const string THIS_NAME = "ReportTools";
/// How to load a font at runtime:
//PrivateFontCollection foo = new PrivateFontCollection();
//foo.AddFontFile(Application.StartupPath + @"\Fonts\c128att.ttf");
//Font fontBarcode = new Font((System.Drawing.FontFamily)foo.Families[0], 24, FontStyle.Regular);
//put an image file under a Images directory within your application root
//Bitmap bitmap = new Bitmap(Convert.ToInt32(szf5.Width)*10, Convert.ToInt32(szf5.Height)*10, ppea.Graphics);
//Graphics.FromImage(bitmap).DrawString(sPoBarcode, fontBarcode, Brushes.Black, 10f, 10f);
//bitmap.Save(Ini.Temp_FileName("Barcode_", "", ".png"), ImageFormat.Png);
//ppea.Graphics.DrawImage(bitmap, xyLoc);
//bitmap.Dispose(); bitmap = null;
public const string EP_ALIGN = "ALIGN";
public const string EP_VISIBLE = "VISIBLE";
public const string EP_WIDTH = "WIDTH";
public const string EP_MARGIN_LEFT = "MARGIN_LEFT";
public const string EP_MARGIN_TOP = "MARGIN_TOP";
public const string EP_MARGIN_RIGHT = "MARGIN_RIGHT";
public const string EP_MARGIN_BOTTOM = "MARGIN_BOTTOM";
public const string EP_FONT_STYLE = "FONT_STYLE";
public static void ReportXPropertiesAdd(ref DataTable rxTbl, bool bDefVisible, float fDefCellWidth, string sDefAlign,
float fDefMarginLeft, float fDefMarginTop, float fDefMarginRight, float fDefMarginBottom,
string sDefFontStyle)
{
// Add Extended Properties for Printing Control
for (int cc = 0; cc < rxTbl.Columns.Count; cc++)
{
rxTbl.Columns[cc].ExtendedProperties.Add(EP_ALIGN, sDefAlign);
rxTbl.Columns[cc].ExtendedProperties.Add(EP_VISIBLE, bDefVisible);
rxTbl.Columns[cc].ExtendedProperties.Add(EP_WIDTH, fDefCellWidth);
rxTbl.Columns[cc].ExtendedProperties.Add(EP_MARGIN_LEFT, fDefMarginLeft);
rxTbl.Columns[cc].ExtendedProperties.Add(EP_MARGIN_TOP, fDefMarginTop);
rxTbl.Columns[cc].ExtendedProperties.Add(EP_MARGIN_RIGHT, fDefMarginRight);
rxTbl.Columns[cc].ExtendedProperties.Add(EP_MARGIN_BOTTOM, fDefMarginBottom);
rxTbl.Columns[cc].ExtendedProperties.Add(EP_FONT_STYLE, sDefFontStyle);
}
}
public static SizeF Data_MaxCellSizeF(Graphics g, ref SizeF szfRow, float fTblScale, Font cellFont, DataView xDV, Int32 iRowCursor, ref string sMaxFieldName)
{
SizeF szfMax = new SizeF(0.0f, 0.0f);
SizeF szfData = new SizeF(0.0f, 0.0f);
szfRow = new SizeF(0.0f, 0.0f);
for (int cc = 0; cc < xDV.Table.Columns.Count; cc++)
{
if (!Convert.ToBoolean(xDV.Table.Columns[cc].ExtendedProperties[EP_VISIBLE]))
{
// skip invisible columns
continue;
}
szfData = g.MeasureString(xDV[iRowCursor][cc].ToString(), cellFont,
Convert.ToInt32((Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_WIDTH]) * fTblScale)));
szfData.Height += Convert.ToInt32(xDV.Table.Columns[cc].ExtendedProperties[EP_MARGIN_TOP])
+ Convert.ToInt32(xDV.Table.Columns[cc].ExtendedProperties[EP_MARGIN_BOTTOM]);
if (szfData.Height > szfMax.Height)
{
szfMax.Height = szfData.Height;
sMaxFieldName = xDV.Table.Columns[cc].ColumnName;
}
if (szfData.Width > szfMax.Width)
{
szfMax.Width = szfData.Width;
}
szfRow.Width += Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_WIDTH]) * fTblScale;
}
szfRow.Height = szfMax.Height;
return szfMax;
}
public static SizeF Header_MaxCellSizeF(Graphics g, ref SizeF szfRow, float fTblScale, Font cellFont, DataTable xTbl, ref string sMaxFieldName)
{
SizeF szfMax = new SizeF(0.0f, 0.0f);
SizeF szfData = new SizeF(0.0f, 0.0f);
szfRow = new SizeF(0.0f, 0.0f);
for (int cc = 0; cc < xTbl.Columns.Count; cc++)
{
if (!Convert.ToBoolean(xTbl.Columns[cc].ExtendedProperties[EP_VISIBLE])) { continue; }
szfData = g.MeasureString(xTbl.Columns[cc].Caption, cellFont,
Convert.ToInt32((Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]) * fTblScale) - 4.0f));
if (szfData.Height > szfMax.Height)
{
szfMax.Height = szfData.Height;
sMaxFieldName = xTbl.Columns[cc].ColumnName;
}
if (szfData.Width > szfMax.Width) { szfMax.Width = szfData.Width; }
szfRow.Width += Convert.ToInt32(Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]) * fTblScale);
}
szfRow.Height = szfMax.Height;
return szfMax;
}
public static float Scale_Factor(DataTable xTbl, float fBoundsWidth)
{
float fScale = 1.0f;
// Calculate the total of all DataGridView Column widths and the Scale Factor to get them to fit on the page
float fTblWidth = 0.0f;
for (int cc = 0; cc < xTbl.Columns.Count; cc++)
{
if (!Convert.ToBoolean(xTbl.Columns[cc].ExtendedProperties[EP_VISIBLE])) { continue; }
fTblWidth += Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]);
}
if (fTblWidth == 0) { fTblWidth = 1; }
else { fScale = fBoundsWidth / fTblWidth; }
return fScale;
}
public static SizeF Print_Table_Header(Graphics g, float fScale, float fPageX, float fPageY,
Font fontHeader, Brush brushFont, Brush brushFill, Pen penGrid,
DataTable xTbl)
{
SizeF szfRow = new SizeF(0.0f, 0.0f);
string sMaxFieldName = "";
float fCellRight = 0.0f;
try
{
// Measure the Maximum Height of the Header Cells' Text and Calculate the Y coordinate of the cell bottom
SizeF szfMaxCell = Header_MaxCellSizeF(g, ref szfRow, fScale, fontHeader, xTbl, ref sMaxFieldName);
szfRow.Height += 2.0f;
float fCellBottom = fPageY + szfRow.Height;
// Print the Table Header shading
g.FillRectangle(brushFill, fPageX + 0.2F, fPageY, szfRow.Width - 0.2F, szfRow.Height);
// Print the Header labels
for (int cc = 0; cc < xTbl.Columns.Count; cc++)
{
if (!Convert.ToBoolean(xTbl.Columns[cc].ExtendedProperties[EP_VISIBLE]))
{
// ignore invisible columns
continue;
}
string sText = xTbl.Columns[cc].Caption;
SizeF szfHeader = g.MeasureString(sText, fontHeader, Convert.ToInt32((Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]) * fScale) - 4.0f));
RectangleF rectfCell;
if (xTbl.Columns[cc].ExtendedProperties[EP_ALIGN].ToString() == "R")
{
// Right Align
rectfCell = new RectangleF(fPageX + ((fCellRight + Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH])) * fScale) - szfHeader.Width - 4.0f, fPageY + 2.0f,
(Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]) * fScale) - 4.0f, szfMaxCell.Height);
}
else if (xTbl.Columns[cc].ExtendedProperties[EP_ALIGN].ToString() == "C")
{
// Center Align
rectfCell = new RectangleF(fPageX + (fCellRight * fScale) + (Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]) * fScale / 2.0f) - (szfHeader.Width / 2.0f),
fPageY + 2.0f, szfHeader.Width, szfMaxCell.Height);
}
else
{
// Left Align
rectfCell = new RectangleF(fPageX + (fCellRight * fScale) + 4.0f, fPageY + 2.0f,
(Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]) * fScale) - 4.0f, szfMaxCell.Height);
}
g.DrawString(sText, fontHeader, brushFont, rectfCell);
fCellRight += Convert.ToSingle(xTbl.Columns[cc].ExtendedProperties[EP_WIDTH]); // Unscaled Right side of completed Cell
if (cc < xTbl.Columns.Count - 1)
{
// Print the Vertical Grid Line. Don't print the last vertical line
g.DrawLine(penGrid, fPageX + (fCellRight * fScale), fPageY, fPageX + (fCellRight * fScale), fCellBottom);
}
}
// Print the Border Lines
g.DrawLine(penGrid, fPageX, fPageY, fPageX, fCellBottom); // Left
g.DrawLine(penGrid, fPageX + szfRow.Width, fPageY, fPageX + szfRow.Width, fCellBottom); // Right
g.DrawLine(penGrid, fPageX, fPageY, fPageX + szfRow.Width, fPageY); // Top
g.DrawLine(penGrid, fPageX, fCellBottom, fPageX + szfRow.Width, fCellBottom); // Botom
}
catch (Exception ex)
{
//Log.Err(ex, THIS_NAME, "Print_Table_Header", Log.LogDevices.CON_LOG_DLG);
}
return szfRow;
}
public static SizeF Print_TableRow(Graphics g, float fScale, float fPageX, float fPageY, float fRowHeight,
Font fontRow, Brush brushFont, Brush brushFill, Pen penGrid,
DataView xDV, Int32 iRowCursor)
{
SizeF szfGridRow = new SizeF(0.0f, 0.0f);
string sMaxFieldName = "";
// Measure the Maximum Height of the Row Cells' Text and Calculate the Y coordinate of the cell bottom
SizeF szfMaxCell = Data_MaxCellSizeF(g, ref szfGridRow, fScale, fontRow, xDV, iRowCursor, ref sMaxFieldName);
if (fRowHeight > szfMaxCell.Height)
{
szfMaxCell.Height = fRowHeight;
szfGridRow.Height = fRowHeight;
}
else
{
fRowHeight = szfMaxCell.Height;
}
float fCellRight = 0.0f;
float fCellBottom = fPageY + fRowHeight;
// Print the Table shading
g.FillRectangle(brushFill, fPageX + 0.2F, fPageY, szfGridRow.Width - 0.2F, fRowHeight);
for (int cc = 0; cc < xDV.Table.Columns.Count; cc++)
{
if (!Convert.ToBoolean(xDV.Table.Columns[cc].ExtendedProperties[EP_VISIBLE]))
{
// skip invisible columns
continue;
}
Font fontCol = (Font)fontRow.Clone();
if (xDV.Table.Columns[cc].ExtendedProperties[EP_FONT_STYLE].ToString() == "B")
{
fontCol = new Font(fontRow, FontStyle.Bold);
}
else if (xDV.Table.Columns[cc].ExtendedProperties[EP_FONT_STYLE].ToString() == "R")
{
fontCol = new Font(fontRow, FontStyle.Regular);
}
else if (xDV.Table.Columns[cc].ExtendedProperties[EP_FONT_STYLE].ToString() == "I")
{
fontCol = new Font(fontRow, FontStyle.Italic);
}
else if (xDV.Table.Columns[cc].ExtendedProperties[EP_FONT_STYLE].ToString() == "S")
{
fontCol = new Font(fontRow, FontStyle.Strikeout);
}
else if (xDV.Table.Columns[cc].ExtendedProperties[EP_FONT_STYLE].ToString() == "U")
{
fontCol = new Font(fontRow, FontStyle.Underline);
}
else
{
fontCol = new Font(fontRow, FontStyle.Regular);
}
string sText = xDV[iRowCursor][cc].ToString();
SizeF szfText = new SizeF(0.0f, 0.0f); // g.MeasureString(sText, fontCol, Convert.ToInt32((Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_WIDTH]) * fScale) - 4.0f));
RectangleF rectfCell;
float epWidth = Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_WIDTH]);
float epRightMargin = Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_MARGIN_RIGHT]);
float epLeftMargin = Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_MARGIN_LEFT]);
float epTopMargin = Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_MARGIN_TOP]);
float epBottomMargin = Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_MARGIN_BOTTOM]);
rectfCell = new RectangleF(fPageX + (fCellRight * fScale),
fPageY + epTopMargin,
(epWidth * fScale) - epLeftMargin - epRightMargin,
fRowHeight - epTopMargin - epBottomMargin);
if (xDV.Table.Columns[cc].ExtendedProperties[EP_ALIGN].ToString().IndexOf("R") == 0)
{
// Right Align
szfText = DrawText_AlignRight(g, sText, fontCol, brushFont,
new SizeF(rectfCell.Width, rectfCell.Height), rectfCell.X, rectfCell.Y);
}
else if (xDV.Table.Columns[cc].ExtendedProperties[EP_ALIGN].ToString().IndexOf("C") == 0)
{
// Center Align
szfText = DrawText_AlignCenter(g, sText.Trim(), fontCol, brushFont, new SizeF(rectfCell.Width, rectfCell.Height), rectfCell.X, rectfCell.Y);
}
else if (xDV.Table.Columns[cc].ExtendedProperties[EP_ALIGN].ToString().IndexOf("LM") == 0)
{
// Left Middle Align
DrawText_AlignLeft(g, sText.Trim(), fontCol, brushFont, new SizeF(rectfCell.Width, rectfCell.Height), rectfCell.X, rectfCell.Y);
}
else
{
// Left Align
DrawText_AlignLeft(g, sText.Trim(), fontCol, brushFont, new SizeF(rectfCell.Width, rectfCell.Height), rectfCell.X, rectfCell.Y);
}
fCellRight += Convert.ToSingle(xDV.Table.Columns[cc].ExtendedProperties[EP_WIDTH]);
if (penGrid.Color != Color.Transparent)
{
if (cc < xDV.Table.Columns.Count - 1)
{
// Print the Vertical Grid Line. Don't print the last vertical line
g.DrawLine(penGrid, fPageX + (fCellRight * fScale), fPageY, fPageX + (fCellRight * fScale), fCellBottom);
}
fontCol.Dispose();
// Print the Rows Bottom Line
g.DrawLine(penGrid, fPageX, fPageY, fPageX, fCellBottom);
g.DrawLine(penGrid, fPageX + szfGridRow.Width, fPageY, fPageX + szfGridRow.Width, fCellBottom);
g.DrawLine(penGrid, fPageX, fPageY, fPageX + szfGridRow.Width, fPageY);
g.DrawLine(penGrid, fPageX, fCellBottom, fPageX + szfGridRow.Width, fCellBottom);
}
}
return szfGridRow;
}
public static Image Report_Logo = null;
public static void Print_PageHeader(PrintPageEventArgs ppea, string[] sTitle, Font[] fontTitle,
float fOriginLeft, float fOriginTop, float fHeadHeight)
{
try
{
if (Report_Logo == null)
{
if (System.IO.File.Exists(Application.StartupPath + @"\Report_Logo.jpg"))
{
Report_Logo = Bitmap.FromFile(Application.StartupPath + @"\Report_Logo.jpg");
}
}
}
catch (Exception ex)
{
//Log.Err(ex, THIS_NAME, "Load Report Logo", Log.LogDevices.CON_LOG_DLG);
}
Pen penHeader1 = new Pen(Color.DarkGray, 0);
try
{
//// Diagnostic
// e.Graphics.DrawRectangle(penHeader1, g_OriginLeft, g_OriginTop, e.MarginBounds.Width, e.MarginBounds.Height);
////
// Print the Page Header, Company Logo, and Report Title
if (Report_Logo != null)
{
ppea.Graphics.DrawImage(Report_Logo, fOriginLeft + 2.0F, fOriginTop + 4.0F, fHeadHeight - 6.0f, fHeadHeight - 6.0f);
ppea.Graphics.DrawRectangle(penHeader1, fOriginLeft, fOriginTop, fHeadHeight - 4.0f, fHeadHeight);
}
ppea.Graphics.DrawRectangle(penHeader1, fOriginLeft, fOriginTop, ppea.MarginBounds.Width, fHeadHeight);
float yPos = fOriginTop + 4.0F;
for (int tt = 0; tt < sTitle.Length; tt++)
{
SizeF szfTitle = ppea.Graphics.MeasureString(sTitle[tt], fontTitle[tt]);
ppea.Graphics.DrawString(sTitle[tt], fontTitle[tt], Brushes.Black, fOriginLeft + (ppea.MarginBounds.Width / 2.0F) - (szfTitle.Width / 2.0F), yPos);
yPos += szfTitle.Height;
}
}
catch (Exception ex)
{
//Log.Err(ex, THIS_NAME, "Print_PageHeader", Log.LogDevices.CON_LOG_DLG);
}
penHeader1.Dispose();
}
#region //// Report Text Routines ////
public static SizeF DrawText_AlignLeft(Graphics g, string sText, Font fontText, Brush brushColor, SizeF szfArea, float xPos, float yPos)
{
SizeF szfText = new SizeF(0.0f, 0.0f);
StringFormat _sfmt = new StringFormat();
_sfmt.Alignment = StringAlignment.Near;
szfText = g.MeasureString(sText, fontText, szfArea, _sfmt);
g.DrawString(sText, fontText, brushColor, new RectangleF(xPos, yPos, szfArea.Width, szfArea.Height), _sfmt);
return szfText;
}
public static SizeF DrawTextBox_AlignLeft(Graphics g, string sText, Font fontText, Brush brushColor, SizeF szfArea, float xPos, float yPos,
float fBorderWidth, Color cBorderColor, Color cFillColor, float fLeftMargin, float fTopMargin)
{
SizeF szfText = new SizeF(0.0f, 0.0f);
StringFormat _sfmt = new StringFormat();
_sfmt.Alignment = StringAlignment.Near;
szfText = g.MeasureString(sText, fontText, szfArea, _sfmt);
RectangleF rect = new RectangleF(xPos, yPos, szfArea.Width, szfArea.Height);
if (cFillColor != Color.Transparent)
{
g.FillRectangle(new SolidBrush(cFillColor), rect);
}
if (fBorderWidth > 0.0f)
{
g.DrawRectangle(new Pen(cBorderColor, fBorderWidth), rect.X, rect.Y, rect.Width, rect.Height);
}
g.DrawString(sText, fontText, brushColor, new RectangleF(xPos + fLeftMargin, yPos + fTopMargin, szfArea.Width, szfArea.Height), _sfmt);
return szfText;
}
public static SizeF DrawText_AlignRight(Graphics g, string sText, Font fontText, Brush brushColor, SizeF szfArea, float xPos, float yPos)
{
SizeF szfText = new SizeF(0.0f, 0.0f);
StringFormat sF = new StringFormat();
sF.Alignment = StringAlignment.Far;
szfText = g.MeasureString(sText, fontText, szfArea, sF);
g.DrawString(sText, fontText, brushColor, new RectangleF(xPos, yPos, szfArea.Width, szfArea.Height), sF);
sF.Dispose();
return szfText;
}
public static SizeF DrawTextBox_AlignRight(Graphics g, string sText, Font fontText, Brush brushColor, SizeF szfArea, float xPos, float yPos,
float fBorderWidth, Color cBorderColor, Color cFillColor, float fRightMargin, float fTopMargin)
{
SizeF szfText = new SizeF(0.0f, 0.0f);
StringFormat sF = new StringFormat();
sF.Alignment = StringAlignment.Far;
szfText = g.MeasureString(sText, fontText, szfArea, sF);
RectangleF rect = new RectangleF(xPos, yPos, szfArea.Width, szfArea.Height);
if (cFillColor != Color.Transparent)
{
g.FillRectangle(new SolidBrush(cFillColor), rect);
}
if (fBorderWidth > 0.0f)
{
g.DrawRectangle(new Pen(cBorderColor, fBorderWidth), rect.X, rect.Y, rect.Width, rect.Height);
}
g.DrawString(sText, fontText, brushColor, new RectangleF(xPos - fRightMargin, yPos + fTopMargin, szfArea.Width, szfArea.Height), sF);
sF.Dispose();
return szfText;
}
public static SizeF DrawText_AlignCenter(Graphics g, string sText, Font fontText, Brush brushColor, SizeF szfArea, float xPos, float yPos)
{
SizeF szfText = new SizeF(0.0f, 0.0f);
StringFormat sF = new StringFormat();
sF.Alignment = StringAlignment.Center;
szfText = g.MeasureString(sText, fontText, szfArea, sF);
g.DrawString(sText, fontText, brushColor, new RectangleF(xPos, yPos + ((szfArea.Height / 2.0f) - (szfText.Height / 2)), szfArea.Width, szfArea.Height), sF);
sF.Dispose();
return szfText;
}
public static SizeF DrawTextBox_AlignCenter(Graphics g, string sText, Font fontText, Brush brushColor, SizeF szfArea,
float xPos, float yPos, float fBorderWidth, Color cBorderColor, Color cFillColor)
{
SizeF szfText = new SizeF(0.0f, 0.0f);
StringFormat sF = new StringFormat();
sF.Alignment = StringAlignment.Center;
szfText = g.MeasureString(sText, fontText, szfArea, sF);
RectangleF rect = new RectangleF(xPos, yPos, szfArea.Width, szfArea.Height);
if (cFillColor != Color.Transparent)
{
g.FillRectangle(new SolidBrush(cFillColor), rect);
}
if (fBorderWidth > 0.0f)
{
g.DrawRectangle(new Pen(cBorderColor, fBorderWidth), rect.X, rect.Y, rect.Width, rect.Height);
}
g.DrawString(sText, fontText, brushColor, new RectangleF(xPos, yPos + ((szfArea.Height / 2.0f) - (szfText.Height / 2)), szfArea.Width, szfArea.Height), sF);
sF.Dispose();
return szfText;
}
#endregion
}
}