允许在课堂上使用第二种形式

时间:2014-05-16 23:46:39

标签: c# windows graphics abstract-class

我正在尝试在项目中以第二种形式创建Creategraphics()。我在我的Form1代码中做了这个:

public partial class Form1 : Form
{

    WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
    Form f = new Form();
    Graphics g;
    TextBox t = new TextBox();
    NotifyIcon ni1 = new NotifyIcon();
    PictureBox p = new PictureBox();
    g = f.CreateGraphics();

然后在我的按钮中点击这种情况:

    private void mclick(object o, EventArgs e)
    {
        Button clickedmc = (Button)o;
        Minecraft m = new Minecraft("Steve (Minecraft)", 2011, "Juego en primera y tercera persona", "Velocidad, resistencia al fuego, variado...");
        m.DrawingAction(f, g);
        ni1.Visible = true;
        ni1.Icon = SystemIcons.Information;
        ni1.ShowBalloonTip(10, "Minecraft", m.Summary(), ToolTipIcon.None);

        this.Invalidate();
        this.Visible = false;
    }

这是课堂上的参考:

    public override void DrawingAction(Form f, Graphics g)
    {
        f.FormClosing += new FormClosingEventHandler(close);

        Pen pen = new Pen(Color.Black, 2);

        f.Visible = true;
        f.Width = 600;
        f.Height = 400;
        f.MaximizeBox = false;
        f.MinimizeBox = false;

        g.DrawLine(pen, 100, 100, 200, 200);

    }

但是除了绘画之外,第二张表格会做其他所有事情。在绘制之前是否需要在“f”中添加属性?

我添加答案。我参考了Dour在评论中给我的参考:P

public override void DrawingAction(Form f,PictureBox p)         {             f.FormClosing + = new FormClosingEventHandler(close);             p.Paint + = new PaintEventHandler(paint);

        //Pen pen = new Pen(Color.Black, 2);

        f.Visible = true;
        f.Width = 600;
        f.Height = 400;
        f.MaximizeBox = false;
        f.MinimizeBox = false;

        p.Visible = true;
        p.Enabled = true;
        p.Dock = DockStyle.Fill;
        p.BackColor = Color.BlueViolet;
        p.BringToFront();
        p.Image = Image.FromFile("h.png"); //This image is perfect to fit in a corner of the form, I will add it to Paint event to redraw it everytime I make another drawing :P 


    }

    //
    private void close(Object o, FormClosingEventArgs e)
    {
        Form1 f1 = new Form1();
        f1.Visible = true;
    }
    private void paint(Object o, PaintEventArgs P)
    {
        Graphics g = P.Graphics;
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        g.DrawLine(Pens.Black, 100, 100, 200, 200);
    }
}

0 个答案:

没有答案