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);
    }

     

  • 相关阅读:
    Jmeter之CSV文件读取
    性能计数器及性能分析方法
    性能测试的应用领域
    动态加载JS文件方法总结
    handler method 参数绑定常用注解
    A4纸网页打印
    page-break-before和page-break-after 实现分页打印
    $.ajax 中的contentType
    @Controller和@RestController的区别?
    web页面内容打印总结
  • 原文地址:https://www.cnblogs.com/myhappylife/p/3051067.html
Copyright © 2011-2022 走看看