zoukankan      html  css  js  c++  java
  • winform加载时,为什么画图不执行了

    今天看C#图形处理,发现一个问题,不知道是我的原因,还是确实存在

    设计界面

    后台代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace Graphic_Processing
    {
    public partial class DrawLine : Form
    {
    public DrawLine()
    {
    InitializeComponent();
    }

    private void DrawLine_Load(object sender, EventArgs e)
    {
      Pen redpen = new Pen(Color.Red,10);
      Point p1 = new Point(10,50);
      Point p2 = new Point(10,200);
      Graphics g = this.CreateGraphics();
      g.DrawLine(redpen, p1, p2);
    }

    private void button1_Click(object sender, EventArgs e)
    {
      Pen redpen = new Pen(Color.Black, 10);
      Point p1 = new Point(10, 50);
      Point p2 = new Point(200, 50);
      Graphics g = this.CreateGraphics();
      g.DrawLine(redpen, p1, p2);
    }
    大家猜猜会出现什么情况啊,

    程序加载时:

    按钮点击时

    为什么会出现这样的问题了,我真的不知道啊。很好奇啊,如果哪位大师知道,请告诉我原因吧

    想了想可能是窗体重绘的结果,把原来的给重绘掉了

    如果把那段代码这么写,就不会出错了

    private void DrawLine_Paint(object sender, EventArgs e)
    {
      Pen redpen = new Pen(Color.Red,10);
      Point p1 = new Point(10,50);
      Point p2 = new Point(10,200);
      Graphics g = this.CreateGraphics();
      g.DrawLine(redpen, p1, p2);
    }

     

  • 相关阅读:
    个人作业——软件评测
    软件工程实践2019第五次作业
    18年今日头条笔试第一题题解:球迷(fans)
    游戏2.1版本
    游戏2.0版本 代码
    游戏2.0版本
    改进版游戏代码
    改进版游戏
    2017.1.13之审判日
    找朋友 的内存超限代码
  • 原文地址:https://www.cnblogs.com/myhappylife/p/3051067.html
Copyright © 2011-2022 走看看