TAB键按下时面板错误

时间:2014-05-12 17:31:36

标签: c# winforms

我有一个我画的面板,当我按Tab键时,一切都消失了。

我也有一个textBox,我试着看看我是否通过调用PreviewKeyDown事件按Tab键并检查那里并重新绘制所有内容但它不起作用。

我做错了什么?

这是我在该面板上绘画的方式:

private void PuneFundal(Graphics g)
{
 g.Clear(Color.FromArgb(150, 124, 92));
}

    private void DeseneazaLinie(Graphics g, Point p1, Point p2)
{
     Pen p = new Pen(Color.Black);
     g.DrawLine(p, p1, p2);
}

private void TrasareLinii(Graphics g)
{
     for (int i = 6, k = 0; k < 20; i += 16, k++)
         DeseneazaLinie(g, new Point(5, i), new Point(309, i));
     for (int i = 6, k = 0; k < 20; i += 16, k++)
         DeseneazaLinie(g, new Point(i, 5), new Point(i, 309));
}

private void Start_game()
{
     Graphics g = m_off_joc_nou_panel.CreateGraphics();
     PuneFundal(g);
     TrasareLinii(g);
}

我的解决方案:

using System.Drawing; //for Graphics and Images and the tool to paint

 public Form1()
{
    Image img = new Bitmap(pictureBox1.Width, pictureBox1.Height);
    pictureBox1.Image = img;
}

private void Start_game()
{
    Image img = pictureBox1.Image;
    Graphics g = Graphics.FromImage(img);

    // here you paint what you whant

    pictureBox1.Image = img;
}

0 个答案:

没有答案