Answer the question
In order to leave comments, you need to log in
How to display an image in a PictureBox on a form?
It is necessary to display in the PictureBox a picture with a chart built by the program in Excel.
In theory, the picture should be in the resources folder, but I don’t understand where it is saved and how to display it in the program itself in the PictureBox in this case?
using System;
using System.Windows.Forms;
using XL = Microsoft.Office.Interop.Excel;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
XL.Application XL1 = new XL.Application(); // Объявляем объект
XL1.Workbooks.Add(); // Добавляем рабочую книгу
// Заполнить ячейки A2 (со 2 по 6)
XL1.ActiveSheet.Cells[1, 2] = textBox1.Text;
XL1.ActiveSheet.Cells[1, 3] = textBox2.Text;
XL1.ActiveSheet.Cells[1, 4] = textBox3.Text;
XL1.ActiveSheet.Cells[1, 5] = textBox4.Text;
XL1.ActiveSheet.Cells[1, 6] = textBox5.Text;
// Добавить новую диаграмму
XL1.Charts.Add();
// Задаем тип графика - диаграммма
XL1.ActiveChart.ChartType = XL.XlChartType.xlPie;
// Отключаем легенду и задаем имя диаграммы
XL1.ActiveChart.HasLegend = false;
XL1.ActiveChart.HasTitle = true;
XL1.ActiveChart.ChartTitle.Characters.Text = "Diagram";
// Сохраняем график в растровом файле
XL1.ActiveChart.Export("myFile.jpg");
//Bitmap myImage = new Bitmap("myFile.jpg");
//pictureBox1.Image = (Image)myImage;
XL1.Visible = true;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question