Administrator

Administrator

  • Admin
  • 2.2k
  • 1.4m

Layout problem

Mar 11 2003 5:32 PM
Hi! I have to create graphics out of form (for printing), but I have lot of trouble with layout. I tried to draw contents of a text box, but then I realized that spacing between characters in text box is different from spacing DrawString uses. You can see this if you try code below. In the code, text in text box and text for drawing have the same number of Ds, but they clearly have different widths. So does anyone know how to make spacing between chars in DrawString same as system uses to draw TextBox? Thanks! dejaniv System.Windows.Forms.TextBox tb = new System.Windows.Forms.TextBox(); System.Drawing.Font font = new System.Drawing.Font("Arial", 16); tb.Left = 0; tb.Top = 50; const string str = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"; tb.Text = str; tb.Font = font; tb.BorderStyle = System.Windows.Forms.BorderStyle.None; tb.Width = 600; System.Windows.Forms.Panel pan1 = new System.Windows.Forms.Panel(); pan1.Left = 30; pan1.Top = 50; pan1.Width = 650; pan1.Height = 300; System.Windows.Forms.Form frm = new System.Windows.Forms.Form(); pan1.Parent = frm; tb.Parent = pan1; frm.Width = 700; frm.Show(); System.Drawing.Graphics g = pan1.CreateGraphics(); g.PageUnit = System.Drawing.GraphicsUnit.Pixel; g.DrawString(str, tb.Font, new System.Drawing.SolidBrush(System.Drawing.Color.Red), -5, 70);

Answers (1)