我想问一下,如何将文件中的文本直接打印到pictureBox中。目前,我的程序应该这样做,但它失败了,我认为原因是,我强迫containerBox到程序的前面。目前,图片盒本身是黑色的,但这是出于测试目的。
代码:
for (int i = 0; i < fileitems.Length; i++)
{
containerBox.Add(new PictureBox());
//PictureBox pBox = new PictureBox();
containerBox[i].Name = "cb" + i;
containerBox[i].Location = new Point(Convert.ToInt32(b*0.05), curB);
containerBox[i].Size = new Size(Convert.ToInt32(b*0.9),Convert.ToInt32(a/5));
containerBox[i].BackColor = Color.Black;
containerBox[i].Dock = DockStyle.Left;
containerBox[i].Anchor = AnchorStyles.None;
//containerBox[i].Paint += PBox_Paint;
j = containerBox[i].CreateGraphics();
using (Font test1 = new Font("Arial", 14))
{
j.DrawString(fileitems[i],test1,Brushes.Blue,new Point(2,2));
}
//this.Controls.Add(containerBox[i]);
//containerBox.Add(pBox);
this.Controls.Add(containerBox[i]);
containerBox[i].BringToFront();
curB = Convert.ToInt32(containerBox[i].Location.Y+(a/5)+25);
}
正如你所看到的,我试过这样做,我可以画画,但后来我无法访问文件或读取数据。下面你会看到paint事件中的代码
代码:
private void PBox_Paint(object sender, PaintEventArgs e)
{
/*
using (Font test1 = new Font("Arial", 14))
{
e.Graphics.DrawString("test", test1, Brushes.Blue, new Point(3, 3));
}*/
}
如何从文件中读取文本,然后将其打印到图片框的左侧?