Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#/Windows窗体:窗体';s的绘制代码未被执行_C#_Windows_Forms_Paint - Fatal编程技术网

C#/Windows窗体:窗体';s的绘制代码未被执行

C#/Windows窗体:窗体';s的绘制代码未被执行,c#,windows,forms,paint,C#,Windows,Forms,Paint,几小时前,我发布了一个类似但不太具体的问题,但情况发生了变化。我正在开发一个程序,可以转换图形,在窗体左上角的面板中显示它们。它以前画得很好,但现在不行,我无法撤消、加载旧版本等。以前,该应用程序甚至对菜单中的事件以及绘画都没有响应。我开始了一个新的项目,并启动和运行,菜单工作,我带来了按钮和东西。但它仍然不会在面板中绘制轴和网格线。我在主窗体的paint处理程序和splitContainer2_Panel1_paint处理程序中都设置了断点,这两个处理程序都应该进行工作,但这里的代码甚至没有被

几小时前,我发布了一个类似但不太具体的问题,但情况发生了变化。我正在开发一个程序,可以转换图形,在窗体左上角的面板中显示它们。它以前画得很好,但现在不行,我无法撤消、加载旧版本等。以前,该应用程序甚至对菜单中的事件以及绘画都没有响应。我开始了一个新的项目,并启动和运行,菜单工作,我带来了按钮和东西。但它仍然不会在面板中绘制轴和网格线。我在主窗体的paint处理程序和splitContainer2_Panel1_paint处理程序中都设置了断点,这两个处理程序都应该进行工作,但这里的代码甚至没有被执行。我有一个计时器,它是活动的,并且每100毫秒使整个表单无效,那么为什么不调用paint事件处理程序呢?帮忙

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;
using System.IO;

namespace TransformerA
{
public partial class Transformer : Form
{
    /* Initialize parameters */
    private bool drawAxes = true;
    private bool drawGrid = true;

    private List<ObjectSettings> dispObjects = new List<ObjectSettings>();


    /* Initialize form */

    public Transformer()
    {
        InitializeComponent();
    }

    private void Transformer_Load(object sender, EventArgs e)
    {
        // Populate available objects listbox
        string currentDir = Directory.GetCurrentDirectory();
        string[] fileEntries = Directory.GetFiles(currentDir + @"\Objects");
        foreach (string s in fileEntries) {
            int start = s.LastIndexOf(@"\");
            int end = s.LastIndexOf(@".");
            availObjectsListBox.Items.Add(s.Substring(start + 1, end - start - 1));
        } // end foreach
    }



    /* Paint graphics */

    // Paint main form
    private void Transformer_Paint(object sender, PaintEventArgs e)
    {
        splitContainer2_Panel1_Paint(sender, e);
    }

    // Paint graphics panel
    private void splitContainer2_Panel1_Paint(object sender, PaintEventArgs e)
    {
        Rectangle r = splitContainer2.Panel1.ClientRectangle;
        //Graphics g = splitContainer2.Panel1.CreateGraphics();
        Graphics g = e.Graphics;
        Pen axisPen = new Pen(Color.Gray, 2.0f);
        Pen gridPen = new Pen(Color.Gray, 1.0f);

        g.Clear(Color.Blue);

        if (drawAxes) {
            g.DrawLine(axisPen, r.Left + 0.5f * r.Width, r.Top, r.Left + 0.5f * r.Width, r.Bottom);
            g.DrawLine(axisPen, r.Left, r.Top + 0.5f * r.Height, r.Right, r.Top + 0.5f * r.Height);
        }

        if (drawGrid) {
            // Vertical lines
            int xVal = 0;
            int xCenter = r.Width / 2;
            g.DrawLine(gridPen, xCenter, r.Top, xCenter, r.Bottom);
            for (int i = 0; i < 10; i++) {
                xVal += r.Width / 20;
                g.DrawLine(gridPen, xCenter + xVal, r.Top, xCenter + xVal, r.Bottom);
                g.DrawLine(gridPen, xCenter - xVal, r.Top, xCenter - xVal, r.Bottom);
            }

            // Horizontal lines
            int yVal = 0;
            int yCenter = r.Height / 2;
            g.DrawLine(gridPen, r.Left, yCenter, r.Right, yCenter);
            for (int i = 0; i < 10; i++) {
                yVal += r.Height / 20;
                g.DrawLine(gridPen, r.Left, yCenter + yVal, r.Right, yCenter + yVal);
                g.DrawLine(gridPen, r.Left, yCenter - yVal, r.Right, yCenter - yVal);
            }
        }



        // foreach object in displayed objects
        // keep list of displayed objects and their settings (make struct)


        g.Dispose();
        axisPen.Dispose();
        gridPen.Dispose();
    }


    /* File menu */

    private void saveImageToolStripMenuItem_Click(object sender, EventArgs e)
    {

    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Close();
    }


    /* Options menu */

    private void axesOnoffToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (drawAxes == true)
            drawAxes = false;
        else
            drawAxes = true;
    }

    private void gridOnoffToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (drawGrid == true)
            drawGrid = false;
        else
            drawGrid = true;
    }


    /* Help menu */

    private void helpToolStripMenuItem_Click(object sender, EventArgs e)
    {
        AboutBox dlg = new AboutBox();
        dlg.ShowDialog();
    }


    /* Other */

    private void timer1_Tick(object sender, EventArgs e)
    {
        Invalidate();
    }
}
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用System.IO;
名称空间转换
{
公共部分类转换器:表单
{
/*初始化参数*/
私有布尔图轴=真;
private bool drawGrid=true;
私有列表dispObjects=新列表();
/*初始化表单*/
公共变压器()
{
初始化组件();
}
私有无效转换器加载(对象发送器、事件参数e)
{
//填充可用对象列表框
字符串currentDir=Directory.GetCurrentDirectory();
字符串[]fileEntries=Directory.GetFiles(currentDir+@“\Objects”);
foreach(文件项中的字符串s){
int start=s.LastIndexOf(@“\”);
int end=s.LastIndexOf(@“);
添加(s.Substring(start+1,end-start-1));
}//结束foreach
}
/*绘画图形*/
//油漆主模板
私有void Transformer_Paint(对象发送器,PaintEventArgs e)
{
拆分容器2_面板1_油漆(发送方,e);
}
//绘制图形面板
私有void splitContainer2_Panel1_Paint(对象发送器,PaintEventArgs e)
{
矩形r=拆分容器2.Panel1.ClientRectangle;
//Graphics g=splitContainer2.Panel1.CreateGraphics();
图形g=e.图形;
笔轴笔=新笔(颜色:灰色,2.0f);
钢笔网格笔=新钢笔(颜色:灰色,1.0f);
g、 清晰(颜色:蓝色);
if(牵引轴){
g、 抽绳(axisPen,右左+0.5f*r.宽度,右上,右左+0.5f*r.宽度,右下);
g、 抽绳(axisPen,右左,右上+0.5f*r高度,右,右上+0.5f*r高度);
}
if(绘图网格){
//垂直线
int xVal=0;
int xCenter=r.宽度/2;
g、 抽绳(网格、xCenter、右上角、xCenter、右下角);
对于(int i=0;i<10;i++){
xVal+=r.宽度/20;
g、 抽绳(网格笔、xCenter+xVal、右上角、xCenter+xVal、右下角);
g、 抽绳(网格笔,xCenter-xVal,右上角,xCenter-xVal,右下角);
}
//水平线
int-yVal=0;
内圆心=右高/2;
g、 抽绳(网格,左、右、中、右、中);
对于(int i=0;i<10;i++){
yVal+=r.高度/20;
g、 抽绳(网格线,右左,圆心+yVal,右,圆心+yVal);
g、 抽绳(网格线,右左,圆心-yVal,右,圆心-yVal);
}
}
//显示对象中的foreach对象
//保留显示对象及其设置的列表(生成结构)
g、 处置();
Dispose();
Dispose();
}
/*文件菜单*/
私有void saveImageToolStripMenuItem\u单击(对象发送方,事件参数e)
{
}
private void exitToolStripMenuItem\u单击(对象发送者,事件参数e)
{
Close();
}
/*选项菜单*/
私有void axesOnoffToolStripMenuItem_单击(对象发送方,事件参数e)
{
如果(drawAxes==true)
drawAxes=false;
其他的
drawAxes=真;
}
私有void gridOnoffToolStripMenuItem\u单击(对象发送方,事件参数e)
{
如果(drawGrid==true)
drawGrid=false;
其他的
drawGrid=true;
}
/*帮助菜单*/
私有无效帮助工具StripMenuItem\u单击(对象发送者,事件参数e)
{
AboutBox dlg=新的AboutBox();
dlg.ShowDialog();
}
/*其他*/
私有无效计时器1_刻度(对象发送方,事件参数e)
{
使无效();
}
}
}

哎呀,修好了,我需要从设计器中添加事件处理程序。。。我只是从旧的非工作版本中粘贴了处理程序代码,因此它没有将所需的代码添加到设计器代码中。仍然不明白它为什么以前停止工作,但至少现在正在运行。

您是否已将Transformer_Paint和splitContainer2_Panel1_Paint例程连接到它们的事件?