Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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# 更新图片框控件时出现的问题_C#_Winforms - Fatal编程技术网

C# 更新图片框控件时出现的问题

C# 更新图片框控件时出现的问题,c#,winforms,C#,Winforms,我在同一窗体上有两个控件。两个控件都包含一个控件。一个listview是在VisualStudio中使用图形编辑器创建的。这一次没有引起任何问题。另一个listview是在运行时以编程方式创建的。我已经为每个控件定义了一个事件处理程序,当热项发生变化时调用这些控件,并且它们都在应该触发的时候触发。两个事件处理程序调用相同的代码来更新picturebox控件。问题在于,当程序定义的listview要求picturebox更新时,picturebox不会得到更新。我确信事件处理程序正在被调用,因为我

我在同一窗体上有两个控件。两个控件都包含一个控件。一个listview是在VisualStudio中使用图形编辑器创建的。这一次没有引起任何问题。另一个listview是在运行时以编程方式创建的。我已经为每个控件定义了一个事件处理程序,当热项发生变化时调用这些控件,并且它们都在应该触发的时候触发。两个事件处理程序调用相同的代码来更新picturebox控件。问题在于,当程序定义的listview要求picturebox更新时,picturebox不会得到更新。我确信事件处理程序正在被调用,因为我的代码会写入文本文件并更新图片框。文本文件会更新,但图片框不会更新。我尝试过更新、失效和刷新PicutureBox以及父窗体,但我就是无法更新它

我不确定这是ObjectListView问题还是标准WinForms问题。我意识到我的问题非常模糊,但我不知道如何在不发布所有代码的情况下澄清它。如有任何建议,将不胜感激

以下是事件处理程序调用的代码:

    public void ShowBitmap(object sender, HotItemChangedEventArgs e, ObjectListView lv, string type)
    {

        ObjectListView olv = sender as ObjectListView;
        if (sender == null)
        {
            return;
        }

        switch (e.HotCellHitLocation)
        {
            case HitTestLocation.Nothing:
                break;
            case HitTestLocation.Group:
                break;
            case HitTestLocation.GroupExpander:
                break;
            default:
                if (e.HotColumnIndex == 0)
                {
                    pictureBox1.Hide();
                    pictureBox1.BorderStyle = BorderStyle.FixedSingle;
                    int rowIndex = e.HotRowIndex;
                    string text = "";
                    if (type == "Main Parts")
                    {
                        TypedObjectListView<MainRadanProjectPartsPart> tlist = new TypedObjectListView<MainRadanProjectPartsPart>(lv);
                        text = tlist.Objects[rowIndex].Symbol;
                    }
                    else if (type == "Parts")
                    {
                        TypedObjectListView<RadanProjectPartsPart> tlist = new TypedObjectListView<RadanProjectPartsPart>(lv);
                        text = tlist.Objects[rowIndex].Symbol;
                    }
                    else if (type == "Nests")
                    {
                        TypedObjectListView<MainRadanProjectNestsNest> tlist = new TypedObjectListView<MainRadanProjectNestsNest>(lv);
                        text = tlist.Objects[rowIndex].FileName;
                    }

                    if (text != null)
                    {
                        Point screenCoords = Cursor.Position;
                        Point controlRelatedCoords = lv.PointToClient(screenCoords);

                        if (controlRelatedCoords.Y < oldCursorPosition.Y)
                        {
                            pictureBox1.Location = controlRelatedCoords;
                            int xPos = controlRelatedCoords.X;
                            int yPos = controlRelatedCoords.Y + 60;
                            pictureBox1.Location = new Point(xPos, yPos);
                        }
                        else if (controlRelatedCoords.Y > oldCursorPosition.Y)
                        {
                            pictureBox1.Location = controlRelatedCoords;
                            int xPos = controlRelatedCoords.X;
                            //int yPos = controlRelatedCoords.Y - pictureBox1.Height;
                            int yPos = controlRelatedCoords.Y - pictureBox1.Height + 30;
                            pictureBox1.Location = new Point(xPos, yPos);
                        }

                        pictureBox1.Show();
                        pictureBox1.BringToFront();
                        olvTreeViewMainParts.Focus();
                        lv.Focus();
                        pictureBox1.Visible = true;
                        DrawSymbol(text);

                        oldCursorPosition = controlRelatedCoords;   // save the cursor position to track cursor direction between calls
                    }
                    else
                    {
                        DrawSymbol("");
                    }
                }
                else
                {
                    pictureBox1.Hide();
                }
                break;
        }
    }

旁注:“普通控件”是指在.designer.cs文件中有代码的控件?只要看看那里,看看安装程序是否与运行时创建的完全不同……实际控件之间没有区别,区别在于代码编写的方式和位置。一个是你自己写的,另一个是由设计器的默认值自动生成的,正如@ AlexeiLevenkov所说的,你可以在.Designer .CS文件中找到代码,你应该考虑更新你的问题…你的问题不是“两者之间的区别是什么……”而是“我试图更新此控件,但它没有更新。”如果你询问你的问题,你会得到更好的回答,而不是其他因素可能起作用。有点像XY问题。XY问题是询问您试图解决的问题,而不是实际问题。也就是说,您正试图解决问题X,您认为解决方案Y可行,但当您遇到问题时,您不是询问X,而是询问Y。显示调用函数的代码,而不是函数本身。另外,
pictureBox1
在哪里声明?
     // track the cursor as it moves over the items in the listview
    private void olvPartsListView_HotItemChanged(object sender, HotItemChangedEventArgs e)
    {
        ShowBitmap(sender, e, olvPartsListView, "Parts"); 
    }