Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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# WindowsFormHost绘制事件未触发_C#_.net_Windowsformshost - Fatal编程技术网

C# WindowsFormHost绘制事件未触发

C# WindowsFormHost绘制事件未触发,c#,.net,windowsformshost,C#,.net,Windowsformshost,我在WPF应用程序中有一个带有WindowsFormHost的面板。最终,我需要能够单击并绘制点。我让它在一个单独的WinForm窗体中完全工作。。。但由于某些原因,调用Invalidate()时,绘制事件根本不会触发!单击事件肯定会在单击时出现消息框时触发。尽管如此,油漆上一点也没有露出。不明白为什么为了我的生命。。。这是密码 XML: 编辑: 为了进一步检查paint事件是否是问题,我添加了行g.FillEllipse(s,400400)编码到单击事件中,它成功地绘制了椭圆。不太像WPF,但

我在WPF应用程序中有一个带有WindowsFormHost的面板。最终,我需要能够单击并绘制点。我让它在一个单独的WinForm窗体中完全工作。。。但由于某些原因,调用Invalidate()时,绘制事件根本不会触发!单击事件肯定会在单击时出现消息框时触发。尽管如此,油漆上一点也没有露出。不明白为什么为了我的生命。。。这是密码

XML:

编辑:


为了进一步检查paint事件是否是问题,我添加了行
g.FillEllipse(s,400400)编码到单击事件中,它成功地绘制了椭圆。

不太像WPF,但我猜应该添加以下内容:

<WindowsFormsHost.Child>
  <wf:Panel x:Name="wfSurface" Paint="wfSurface_Paint"
                               MouseClick="wfSurface_MouseClick"/>
</WindowsFormsHost.Child>


我看到了mouseclick事件,但我看不到您订阅paint事件的位置。@LarsTech:那不是
私有void wfSurface\u paint(对象发送者,System.Windows.Forms.PaintEventArgs e)
?由
wfSurface.Invalidate()激发:
?不。这是方法,但我认为没有任何东西在调用它。也不知道这是否重要,但当我将鼠标悬停在
wfSurface.Invalidate()上时在visual Studio中出现“Systems.Windows.Forms.Panel MainWindow.wfSurface”。真的吗??这正是我在WinForms中所做的。。。我需要做一些初始化吗?我该怎么称呼它呢?
private void wfSurface_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        Graphics g;
        g = wfSurface.CreateGraphics();
        epanet epa = epanet.GetInstance();
        SolidBrush s = new SolidBrush(System.Drawing.Color.Blue);
        g.FillEllipse(s, Convert.ToInt32(epa.xCord), Convert.ToInt32(epa.yCord), 50, 50);
        g.FillEllipse(s, 400, 400, 500, 500);
        MessageBox.Show("paint event fired");
    }

    private void wfSurface_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        epanet epa = epanet.GetInstance();
        epa.xCord = e.X;
        epa.yCord = e.Y;
        MessageBox.Show("xCord is:  " + e.X.ToString());
        wfSurface.Invalidate();
    }
<WindowsFormsHost.Child>
  <wf:Panel x:Name="wfSurface" Paint="wfSurface_Paint"
                               MouseClick="wfSurface_MouseClick"/>
</WindowsFormsHost.Child>