简体   繁体   中英

Drawn lines on panel dissapear when scrollbars are shown

I have a panel where the AutoScroll property is tru(AutoSize is false). Using a variable Graphics gi draw some lines on this panel. The problem is when the ScrollBars appear, all the lines that created during the execution, dissapear. Any idea why and some possible solution??

I tried to use another panel where i could draw the lines, setting its backcolor to trasparent but didn't seem too good because other stuff i have like textboxes etc are hiding from the new panel

Here is some of my code and some screenshots hoping they will help! Thank you

 private void fwd_exmem_hazard()
    {
        int poss = 0;
        int poss2 = poss+1;
        List<mystruct> pipe = new List<mystruct>();
        pipe = queue1.ToList();
        while (poss2 < fwd1_list.Count)
        {
            try
            {
                if (((fwd1_list[poss].cycle == 3) && (fwd1_list[poss].rd == fwd1_list[poss2].rs) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0))
                    || (fwd1_list[poss].cycle == 3 && (fwd1_list[poss].rd == fwd1_list[poss2 + 1].rs) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0)))
                {

                    Graphics g; g = panel3.CreateGraphics();
                    Pen pen = new Pen(Color.Red);
                    Point p1 = new Point(pipe[poss].location.X+30, pipe[poss].location.Y);
                    Point p2 = new Point(pipe[poss2].location.X-10, pipe[poss2].location.Y);
                    g.DrawLine(pen,p1, p2);
                    fwd_count++;
                }
                if (((fwd1_list[poss].cycle == 3) && (fwd1_list[poss].rd == fwd1_list[poss2].rt) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0))
                    || (fwd1_list[poss].cycle == 3 && (fwd1_list[poss].rd == fwd1_list[poss2 + 1].rt) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0)))
                {

                    Graphics g; g = panel3.CreateGraphics();
                    Pen pen = new Pen(Color.Orange);
                    Point p1 = new Point(pipe[poss].location.X+30, pipe[poss].location.Y);
                    Point p2 = new Point(pipe[poss2].location.X-10, pipe[poss2].location.Y);
                    g.DrawLine(pen, p1, p2);
                    fwd_count++;

                }
                poss++; poss2++;
            }
            catch { break; }
        }

    }

mystruct is a custom structure i created, queue1 is a global Queue

滚动条出现之前

滚动条出现后

之所以发生这种情况,是因为在面板刷新时,它会调用paint事件并从头开始重绘自身,因此行消失了,因此需要将代码放入Panel Paint事件中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM