WPF - print datagrid contents - c#
I Have looked around and I have not found a solid answeer to this question. I am trying to print my datagrid content when I press a button, the main problem is that my datagrid has too much data and only whatever is shown in the screen is printing. I need It to print all data and if the data does not fit in current page create a mew page and print the rest.
Here is my solution printing Data Grid View using System.Drawing.Printing
using System.Drawing.Printing;
private int PageCounter { get; set; } = 1;
private int RowCounter { get; set; }
Print Button
private void BtnPrint_Click(object sender, EventArgs e)
{
PrintDocument printDoc = new PrintDocument();
IQueryable<PaperSize> paperSizes = printDoc.PrinterSettings.PaperSizes.Cast<PaperSize>().AsQueryable();
printDoc.DefaultPageSettings.PaperSize = paperSizes.First(ps => ps.Kind == PaperKind.A4);
printDoc.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
pageCounter = 1;
printDoc.PrintPage += PrintDoc_PrintPage;
printDoc.Print();
}
Print Method
private void Print_Document(object sender, PrintPageEventArgs e)
{
if (e.Graphics == null)
throw new Exception("Unable to find page Graphics!");
int left = 30;
int cellLeft = left;
int top = 50;
int cellWidth = 0;
int headerHeight = 30;
string headerName = string.Empty;
string cellValue = string.Empty;
Rectangle rect = new();
int pageWidth = e.PageSettings.PaperSize.Width - 60;
int pageHeight = e.PageSettings.PaperSize.Height - 100;
Graphics g = e.Graphics;
Font font = new(FontFamily, 9);
Pen p = new(Brushes.Black, 1f);
Pen borderP = new(new SolidBrush(Color.FromArgb(240, 240, 240)), 1f);
StringFormat stringFormatCenter = new()
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
StringFormat stringFormatRight = new()
{
Alignment = StringAlignment.Far,
LineAlignment = StringAlignment.Center
};
StringFormat stringFormatLeft = new()
{
LineAlignment = StringAlignment.Center
};
if (PageCounter == 1)
{
g.DrawRectangle(p, new Rectangle(left, top, pageWidth, 30));
top += 30;
g.DrawRectangle(p, new Rectangle(left, top, pageWidth, 30));
top += 30;
g.DrawRectangle(p, new Rectangle(left, top, pageWidth, 30));
top += 30;
g.DrawRectangle(p, new Rectangle(left, top, pageWidth / 2, 30));
g.DrawRectangle(p, new Rectangle(left + (pageWidth / 2), top, pageWidth / 2, 30));
top += 30;
top = 50;
g.DrawString
("Company Name"
, new Font(FontFamily, 14f, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left, top, pageWidth, 30)
, stringFormatCenter);
top += 30;
g.DrawString
("Business Type"
, new Font(FontFamily, 12f, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left, top, pageWidth, 30)
, stringFormatCenter);
top += 30;
g.DrawString
("Report Name"
, new Font(FontFamily, 12f, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left, top, pageWidth, 30)
, stringFormatCenter);
top += 30;
g.DrawString
("User Name: " + SelectedUser.Name
, new Font(FontFamily, 9, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left, top, pageWidth / 2, 30)
, stringFormatLeft);
g.DrawString
("Report Date: " + DateTime.Now.ToString("dd-mm-yyyy hh:mm:ss")
, new Font(FontFamily, 9, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left + (pageWidth / 2), top, pageWidth / 2, 30)
, stringFormatRight);
top += 30;
g.DrawString
("Login Id: " + SelectedUser.LoginId
, new Font(FontFamily, 9, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left, top, pageWidth / 2, 30)
, stringFormatLeft);
g.DrawString
("Printed By: " + LoggedUser.Name
, new Font(FontFamily, 9, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left + (pageWidth / 2), top, pageWidth / 2, 20)
, stringFormatRight);
top += 30;
g.DrawString
("Rights detail as follows:"
, new Font(FontFamily, 8, FontStyle.Bold)
, Brushes.Black
, new Rectangle(left, top, pageWidth, 20)
, stringFormatLeft);
top += 20;
}
g.FillRectangle(new SolidBrush(Color.FromArgb(234, 239, 250)), new Rectangle(left, top, pageWidth, headerHeight));
foreach (string name in PrintableRights.First().GetType().GetProperties().Select(p => p.Name))
{
if (name.Equals("SrNo"))
{
headerName = "Sr #";
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 8);
}
else if (name.Equals("Code"))
{
headerName = "Code";
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 20);
}
else if (name.Equals("Name"))
{
headerName = "Name";
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 57);
}
else if (name.Equals("HasRight"))
{
headerName = "Right";
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 15);
}
rect = new Rectangle(cellLeft, top, cellWidth, headerHeight);
g.DrawString(headerName, new Font(FontFamily, 10, FontStyle.Bold), Brushes.Black, rect, stringFormatLeft);
cellLeft += cellWidth;
}
top += headerHeight;
cellLeft = left;
while (RowCounter < PrintableRights.Count())
{
object row = PrintableRights.ElementAt(RowCounter);
cellLeft = left;
foreach (string name in row.GetType().GetProperties().Select(prop => prop.Name))
{
if (name.Equals("SrNo"))
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 8);
else if (name.Equals("Code"))
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 20);
else if (name.Equals("Name"))
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 57);
else if (name.Equals("HasRight"))
cellWidth = Convert.ToInt32(Convert.ToDecimal(pageWidth) / 100 * 15);
rect = new Rectangle(cellLeft, top, cellWidth, 20);
g.DrawRectangle(borderP, rect);
PropertyInfo? prop = row.GetType().GetProperty(name);
if (prop != null)
{
if (prop.PropertyType == typeof(bool))
{
var val = prop.GetValue(row, null);
if (val != null && (bool)val)
g.DrawString("Yes", font, Brushes.Black, rect, stringFormatLeft);
else if (val != null)
g.DrawString("No", font, Brushes.Black, rect, stringFormatLeft);
}
else if (prop.PropertyType == typeof(int))
{
var val = prop.GetValue(row, null);
if (val != null)
g.DrawString(((int)val).ToString("N0"), font, Brushes.Black, rect, stringFormatRight);
else
g.DrawString(string.Empty, font, Brushes.Black, rect, stringFormatRight);
}
else if (prop.PropertyType == typeof(string))
{
var val = prop.GetValue(row, null);
if(val != null)
g.DrawString((string)val, font, Brushes.Black, rect, stringFormatLeft);
else
g.DrawString(string.Empty, font, Brushes.Black, rect, stringFormatLeft);
}
}
cellLeft += cellWidth;
}
top += 20;
if (RowCounter < PrintableRights.Count() - 1)
{
if (top > pageHeight - 10)
{
RowCounter++;
break;
}
}
RowCounter++;
}
if (RowCounter <= PrintableRights.Count() - 1)
{
if (top + 10 > pageHeight)
{
g.DrawString("Continue....", new Font(FontFamily, 7f), Brushes.Black, e.PageSettings.PaperSize.Width - 200, e.PageSettings.PaperSize.Height - 60);
g.DrawString("Page # " + PageCounter.ToString(), new Font(FontFamily, 7f), Brushes.Black, e.PageSettings.PaperSize.Width - 100, e.PageSettings.PaperSize.Height - 60);
PageCounter++;
e.HasMorePages = true;
}
}
else if (e.HasMorePages)
{
g.DrawString("Continue....", new Font(FontFamily, 7f), Brushes.Black, e.PageSettings.PaperSize.Width - 200, e.PageSettings.PaperSize.Height - 60);
g.DrawString("Page # " + PageCounter.ToString(), new Font(FontFamily, 7f), Brushes.Black, e.PageSettings.PaperSize.Width - 100, e.PageSettings.PaperSize.Height - 60);
PageCounter++;
}
else
{
g.DrawString("Last Page.", new Font(FontFamily, 7f), Brushes.Black, e.PageSettings.PaperSize.Width - 200, e.PageSettings.PaperSize.Height - 60);
g.DrawString("Page # " + PageCounter.ToString(), new Font(FontFamily, 7f), Brushes.Black, e.PageSettings.PaperSize.Width - 100, e.PageSettings.PaperSize.Height - 60);
}
}
Related
How can i ressize my rectangles using mouse events in c#?
I've been drawn multiple rectangles on the picturebox image.I want to resize all that rectangles using mouse events. Can anyone help me out regarding this? public List<rectangle> listRec = new List<rectangle>(); Graphics g; //private Graphics g; Point startPos; Point currentPos; bool drawing; Rectangle r1; Rectangle rect = new Rectangle(); private Rectangle getRectangle() { r1 = new Rectangle( Math.Min(startPos.X, currentPos.X), Math.Min(startPos.Y, currentPos.Y), Math.Abs(startPos.X - currentPos.X), Math.Abs(startPos.Y - currentPos.Y)); return r1; } private void button1_Click(object sender, EventArgs e) { String data; Font font = new Font("Arial", 14); arg1 = Convert.ToInt32(textBox1.Text); arg2 = Convert.ToInt32(textBox2.Text); Rectangle rect = new Rectangle(); rect.Size = new Size(40, 65); for (int x = 0; x < arg1; x++) { // rect.X = x * rect.Width; rect.X = x * (rect.Width + 30) + 73; for (int y = 0; y < arg2; y++) { rect.Y = y * (rect.Height + 35) + 38; listRec.Add(rect); data = rect.ToString(); TextWriter txt = new StreamWriter("E:\\B1Pockets.txt", true); txt.WriteLine(data); txt.Close(); // MessageBox.Show(rect.ToString()); } } foreach (Rectangle rec in listRec) { g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Red, 3); g.DrawRectangle(p, rec); g.DrawString("p1", font, new SolidBrush(Color.Yellow), (rect.Width + 30), 35); g.DrawString("p2", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 60, 35); g.DrawString("p3", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 130, 35); g.DrawString("p4", font, new SolidBrush(Color.Yellow), (rect.Width + 30), (rect.Height + 30) + 40); g.DrawString("p5", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 60, (rect.Height + 30) + 40); g.DrawString("p6", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 130, (rect.Height + 30) + 40); } } I've tried this code to my application.I drawn rectangles in 2*3 manner.and also draw a big rectangle above it.In short my picturebox containing many rectangles and i want to add resizing options for all the rectangles in c#
Can rectangle be split in rows and columns?
private void panel1_Paint(object sender, PaintEventArgs e) { Pen mypen = default(Pen); mypen = new Pen(System.Drawing.Color.Red, 3); mypen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; //For Dash Line in Rectangle Pen mypen1 = default(Pen); mypen1 = new Pen(System.Drawing.Color.Blue, 1); mypen1.DashStyle![enter image description here][2] = System.Drawing.Drawing2D.DashStyle.Dash; //Pen mypen2 =default(Pen); //mypen2 = new Pen(System.Drawing.Color.Yellow, 3); //mypen2.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; //Pen mypen3 = default(Pen); //mypen3 = new Pen(System.Drawing.Color.Violet, 1); //mypen3.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; L1 = Rect1LT.X + 5; T1 = Rect1LT.Y + 5; W1 = Rect1RB.X - Rect1LT.X; H1 = Rect1RB.Y - Rect1LT.Y; e.Graphics.DrawRectangle(mypen, new System.Drawing.Rectangle(L1, T1, W1, H1)); e.Graphics.DrawRectangle(mypen1, new System.Drawing.Rectangle(L1, T1, W1, H1)); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1LT.X, Rect1LT.Y, 10, 10)); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1RT.X, Rect1RT.Y, 10, 10)); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1LB.X, Rect1LB.Y, 10, 10)); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1RB.X, Rect1RB.Y, 10, 10)); e.Graphics.FillRectangle(Brushes.Blue, Rect1LT); e.Graphics.FillRectangle(Brushes.Blue, Rect1RT); e.Graphics.FillRectangle(Brushes.Blue, Rect1LB); e.Graphics.FillRectangle(Brushes.Blue, Rect1RB); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1T.X, Rect1T.Y, 10, 10)); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1R.X, Rect1R.Y, 10, 10)); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1B.X, Rect1B.Y, 10, 10)); e.Graphics.DrawRectangle(Pens.Blue, new System.Drawing.Rectangle(Rect1L.X, Rect1L.Y, 10, 10)); e.Graphics.FillRectangle(Brushes.Blue, Rect1T); e.Graphics.FillRectangle(Brushes.Blue, Rect1R); e.Graphics.FillRectangle(Brushes.Blue, Rect1B); e.Graphics.FillRectangle(Brushes.Blue, Rect1L); DataGridView dg1 = new DataGridView(); //while (!exit) //{ // var time = GetTime(); // Update(time); // Render(time); //} } I want to Divide Rectangle in Rows and Columns and Size of Rows and Column can be changeable at runtime? and No of Rows and Columns also can be changeable? I don't want to split whole rectangle I just want to divide them in rectangle.
Here is a simplfied example: int cols = 7; int rows = 11; private void panel1_Paint(object sender, PaintEventArgs e) { Rectangle Rect = // your Rectangle! Rectangle pRect = Rect; // panel2.ClientRectangle; float width = 1f * pRect.Width / cols; float height = 1f * pRect.Height / rows; using (Pen pen = new Pen(System.Drawing.Color.Blue, 1)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; for (int c = 0; c < cols; c++) for (int r = 0; r < rows; r++) { RectangleF rect = new RectangleF(pRect.X + c * width, pRect.Y + r * height, width, height); e.Graphics.FillRectangle(Brushes.Coral, rect); // e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); } for (int c = 0; c < cols; c++) e.Graphics.DrawLine(pen, pRect.X + c * width, pRect.Y, pRect.X + c * width, pRect.Y + pRect.Height); for (int r = 0; r < rows; r++) e.Graphics.DrawLine(pen, pRect.X, pRect.Y + r * height, pRect.X + pRect.Width, pRect.Y + r * height); e.Graphics.DrawRectangle(Pens.Red, pRect.X, pRect.Y, pRect.Width - 1, pRect.Height - 1); } } Note a few changes: The border color and the fill color must not be the same. The fill must come first or it will overwrite the border I work with floats to fill the panel completely; if the cols and rows don't divide into the panel/rectangle size evenly, the recangles will not all have the same sizes .. At first I have ignored your DashStyle. If you want to have a DashStyle you must completely change your plan! The reason is that if you draw Rectangles in a grid you.. ..either have them overlapping and then the dashes will get in each others way. There is a DashOffset parameter but I don't think it can be twisted to make it work over any grid. ..or you need to draw the rectangles inside the grid cells but then they will be twice a thick and the patterns still will disturb each other. Instead you simply draw only a few lines as shown! Here is my example with Dashes:
Pictureboxes with transparent background
I have two pictureboxes: One in the background with an image in it (picturebox1) and another one,(pic1) were i want to paint something (this background should be transparent.--> pic1.BackColor = Color.Transparent;) It look like that: Everything works great except the font. why does it have a black border? My code looks like that: private void InBitmapZeichnen() { Graphics g1 = Graphics.FromImage(bmp12); g1.PageUnit = GraphicsUnit.Pixel; //g1.InterpolationMode = InterpolationMode.HighQualityBilinear; Font f = new Font("Verdana", 8f); Font f1 = new Font("Verdana", 8f); Font f2 = new Font("Verdana", 10, System.Drawing.FontStyle.Bold); Brush b = new SolidBrush(Color.YellowGreen); Brush b1 = new SolidBrush(Color.YellowGreen); Pen PenRaster = new Pen(Color.Black, 0.1f); if (mnuRaster.Checked == true) { float j = Rohrdurchmesser / (float)(trk.Value + 2); //g1.SmoothingMode = SmoothingMode.HighSpeed; for (int i = pic1.Width / (trk.Value + 2); i <= pic1.Width - pic1.Width / (trk.Value + 2); i += pic1.Width / (trk.Value + 2)) { PointF PRaster1 = new PointF(i, 0); PointF PRaster2 = new PointF(i, pic1.Bottom); PointF PRaster3 = new PointF(0, i+4); PointF PRaster4 = new PointF(pic1.Right, i+4); g1.DrawString((j).ToString("0") + " mm", f, b, new PointF(i + 5, 5)); g1.DrawString((j).ToString("0") + " mm", f, b, new PointF(5, i + 5)); g1.DrawLine(PenRaster, PRaster1, PRaster2); g1.DrawLine(PenRaster, PRaster3, PRaster4); j += Rohrdurchmesser / (float)(trk.Value + 2); } } } When I select a color for backcolor it works fine:
Try use GraphicsPath if you want to draw text on trasparent background: private void InBitmapZeichnen() { Graphics g1 = Graphics.FromImage(bmp12); g1.PageUnit = GraphicsUnit.Pixel; g1.SmoothingMode = SmoothingMode.AntiAlias; //g1.InterpolationMode = InterpolationMode.HighQualityBilinear; Font f = new Font("Verdana", 8f); Font f1 = new Font("Verdana", 8f); Font f2 = new Font("Verdana", 10, System.Drawing.FontStyle.Bold); Brush b = new SolidBrush(Color.YellowGreen); Brush b1 = new SolidBrush(Color.YellowGreen); Pen PenRaster = new Pen(Color.Black, 0.1f); if (mnuRaster.Checked == true) { float j = Rohrdurchmesser / (float)(trk.Value + 2); //g1.SmoothingMode = SmoothingMode.HighSpeed; for (int i = pic1.Width / (trk.Value + 2); i <= pic1.Width - pic1.Width / (trk.Value + 2); i += pic1.Width / (trk.Value + 2)) { PointF PRaster1 = new PointF(i, 0); PointF PRaster2 = new PointF(i, pic1.Bottom); PointF PRaster3 = new PointF(0, i + 4); PointF PRaster4 = new PointF(pic1.Right, i + 4); using (var path = new GraphicsPath()) { path.AddString((j).ToString("0") + " mm", f.FontFamily, (int)f.Style, f.Size, new Point(i + 5, 5), null); path.AddString((j).ToString("0") + " mm", f.FontFamily, (int)f.Style, f.Size, new Point(5, i + 5), null); g1.FillPath(b, path); } //g1.DrawString((j).ToString("0") + " mm", f, b, new PointF(i + 5, 5)); //g1.DrawString((j).ToString("0") + " mm", f, b, new PointF(5, i + 5)); g1.DrawLine(PenRaster, PRaster1, PRaster2); g1.DrawLine(PenRaster, PRaster3, PRaster4); j += Rohrdurchmesser / (float)(trk.Value + 2); } } } As you can see instead of DrawString i used FillPath.
I think need to clear Back Color before you start drawing on picture box. Graphics g1 = Graphics.FromImage(bmp12); // add clear g1.Clear(BackColor); So try this statement in your code...!!!
DrawLine on ComboBox SelectedItemIndex
just wondering if i can draw line on selection index for combobox . ss: http://oi59.tinypic.com/lzdxj.jpg referring to screenshot above: number1 -|> i want to achieve number2 -|> current output that i have for combobox using this code: sample code: void ComboBox1_DrawItem(object sender, ListBoxDrawItemEventArgs e) { float[] location = new float[4]; Pen pen = new Pen(Color.FromArgb(255, 255, 255, 255), 2f); if (e.Item.ToString() == "2") { var q = e.Bounds; pen = new Pen(Color.FromArgb(255, 255, 255, 255), 2f); //Rectangle r = e.Bounds; var x = ComboBox1.Size.Width - 13; location[0] = 10; location[1] = (e.Bounds.Y / 2) + ((e.Bounds.Y + e.Bounds.Height) / 2) + .5f; location[2] = x; location[3] = (e.Bounds.Y / 2) + ((e.Bounds.Y + e.Bounds.Height) / 2) + .5f; e.Graphics.DrawLine(pen, location[0], location[1], location[2], location[3]); e.Handled = true; } if (e.State != DrawItemState.Selected) return; e.Cache.FillRectangle(Color.FromArgb(83, 83, 83), e.Bounds); e.Graphics.DrawLine(pen, location[0], location[1], location[2], location[3]); e.Handled = true; } how can i achieve it? Note: Im using DevExpress ComboBoxEdit
Draws the Highlight over the top of the tabpage
i am using TabControl in my windows form application (c#) and i want draw the Highlight over the top of the tabpage headers using hightlightcolor. http://img4up.com/up2/83871411772596923665.jpg thanks
I hope this will help you. Just apply this below mentioned code in OnDrawItem Event of Tab Control if (e.Index == SelectedIndex) { Rectangle rect = new Rectangle(e.Bounds.X + 4, e.Bounds.Y, e.Bounds.Width - 6, e.Bounds.Height); backColorBrush = new SolidBrush(Color.CornflowerBlue); e.Graphics.FillRectangle(backColorBrush, rect); string tabName = this.TabPages[e.Index].Text; TabPages[e.Index].BackColor = Color.AliceBlue; TabPages[e.Index].BorderStyle = BorderStyle.None; TabPages[e.Index].UseVisualStyleBackColor = false; TabPages[e.Index].RightToLeft = RightToLeft.No; myFormat.Alignment = StringAlignment.Near; myFont = new Font(e.Font, FontStyle.Bold); RectangleF r1 = new RectangleF(e.Bounds.X + 1, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4); foreColorBrush = new System.Drawing.SolidBrush(Color.Black); e.Graphics.DrawString(tabName, myFont, foreColorBrush, r1, myFormat); // e.Graphics.DrawImage(img, new Point(rect.X + (GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y)); } else { myFont = new Font(e.Font, FontStyle.Bold); backColorBrush = new System.Drawing.SolidBrush(Color.CadetBlue); foreColorBrush = new System.Drawing.SolidBrush(Color.Black); TabPages[e.Index].BackColor = Color.AliceBlue; string tabName = TabPages[e.Index].Text; Rectangle rect = new Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height + 1); myFormat.Alignment = StringAlignment.Near; e.Graphics.FillRectangle(backColorBrush, rect); RectangleF r1 = new RectangleF(e.Bounds.X, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4); e.Graphics.DrawString(tabName, myFont, foreColorBrush, r1, myFormat); //e.Graphics.DrawImage(img, new Point(rect.X + (GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y)); } myFormat.Dispose(); myFont.Dispose(); backColorBrush.Dispose(); foreColorBrush.Dispose();