Page 1 of 1

Printing other controls with TeeChart

Posted: Tue May 02, 2006 6:46 am
by 9640166
Hi,

I have other controls on my form under my chart, such as textboxes.

When the user prints, I want to basically print all the controls on the form, not just the chart.

Is there an easy way to integrate this functionality into TeeChart without having to draw each control individually, including the chart, on the form.

Thanks.

Posted: Tue May 02, 2006 10:34 am
by narcis
Hi Agrilink,

Could you please give us more information about that? What do you exactly mean saying "When the user prints"? Does it use TeeChart's print preview or other printing facilities?

Thanks in advance.

Posted: Tue May 02, 2006 11:22 pm
by 9640166
Hi Narcis,

When using TeeChart's "Print" method, eg. "tChart1.Printer.Print(true);" - this only prints the chart as specified in the help. Similarly, the "Preview" method only shows the chart.

On my form, I have other controls such as TextBoxes and CheckBoxes in a panel docked to the bottom of the form and the chart filling the rest of the form.

The TextBoxes display the series values at the cursor position on the X-Axis, so when ever the cursor is moved the values in the TextBoxes are updated.

What I want to do is show the entire form, ie. the chart plus the controls beneath the chart, when doing a Print Preview and Printing the form.

So I've resorted to using .NET's "PrintPreviewDialog" and "PrintDocument" controls.

I can individually draw each control eg:

private void DrawForm(Graphics g)
{
foreach (Control c in this.panel1.Controls)
{
string sType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);

switch (sType)
{
case "CheckBox":

CheckBox chk = (CheckBox)c;

// Use the DrawCheckBox command to draw a checkbox and pass the button state to paint it checked or unchecked
if (chk.Checked)
ControlPaint.DrawCheckBox(g, chk.Left, chk.Top, chk.Height / 2, chk.Height / 2, ButtonState.Checked);
else
ControlPaint.DrawCheckBox(g, chk.Left, chk.Top, chk.Height / 2, chk.Height / 2, ButtonState.Normal);

// Don't forget the checkbox text
g.DrawString(chk.Text, chk.Font, new SolidBrush(chk.ForeColor), chk.Right + chk.Height - g.MeasureString(chk.Text, chk.Font).Width,
chk.Top, new StringFormat());

break;

case "TextBox":

TextBox txt = (TextBox)c;

// Draw a text box by drawing a pushed in button and filling the rectangle with the background color and the text
// of the TextBox control

// First the sunken border
ControlPaint.DrawButton(g, txt.Left, txt.Top, txt.Width, txt.Height, ButtonState.Pushed);

// Then fill it with the background of the textbox
g.FillRectangle(new SolidBrush(txt.BackColor), txt.Left + 1, txt.Top + 1, txt.Width + 2, txt.Height - 2);

// Finally draw the string inside
g.DrawString(txt.Text, txt.Font, new SolidBrush(txt.ForeColor), txt.Left + 2,
txt.Top + txt.Height / 2 - g.MeasureString(txt.Text, txt.Font).Height / 2, new StringFormat());

break;
}
}
}

However, how would I do the same for a TeeChart?

If there's no easier way, I'll create an image such as a bitmap, then use the "DrawImage" method of the Graphics class, before using the above code to draw the rest of the controls on the form.

So to me it seems I can't use TeeChart's printing facilities?

Thanks for your help.

Posted: Wed May 03, 2006 10:31 am
by narcis
Hi Agrilink,

Thanks for the reply. Then you could try using tChart1.Draw(g) which will draw the chart into g.

Posted: Wed May 03, 2006 11:06 pm
by 9640166
Hi Narcis,

That work's equally as well, though using:

Bitmap image = this.tChart1.Chart.Bitmap(width, height);
g.DrawImage(image, xpos, ypos);

I can specify the position to print the chart.
Using tChart1.Draw(g) will only draw the chart at 0,0 coordinates?

Anyway, using either method, a border is drawn along the bottom and up the right side of the chart, even if the background color of the chart is changed from the default.

Is there a way to remove these lines?

Thanks.

Posted: Thu May 04, 2006 10:35 am
by narcis
Hi Agrilink,

You should add the code below to make inner and outer bevels not visible.

Code: Select all

      tChart1.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
      tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;

Posted: Thu May 04, 2006 11:16 pm
by 9640166
Thanks alot Narcis.