582 Star 4.6K Fork 1.1K

冰封一夏 / HZHControls控件库

 / 详情

Lamp控件指定不闪烁时的颜色(比初始颜色少),提示数组越界异常

待办的
创建于  
2021-01-05 10:15

Lamp控件指定不闪烁时的颜色?查了源码并没有发现可以指定最终显示颜色方法(不闪烁)
初始设置2种颜色(RED,LIME)源码中使用了intColorIndex在onPaint用于实现每次闪烁时重绘颜色。当重新指定LampColor=new Color[]{ Color.RED } 为一种颜色时,因为intColorIndex可能会大于1,此时onPaint重绘方法获取的LampColor[intColorIndex]会提示数组越界。

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var g = e.Graphics;
            g.SetGDIHigh();

            Color c1 = lampColor[intColorIndex];//这一行会数组越界
            GraphicsPath path = new GraphicsPath();
            path.AddLine(new Point(m_rectWorking.Left, m_rectWorking.Bottom), new Point(m_rectWorking.Left, m_rectWorking.Top + m_rectWorking.Width));
            path.AddArc(new Rectangle(m_rectWorking.Left, m_rectWorking.Top, m_rectWorking.Width, m_rectWorking.Width), 180f, 180f);
            path.AddLine(new Point(m_rectWorking.Right, m_rectWorking.Top + m_rectWorking.Width), new Point(m_rectWorking.Right, m_rectWorking.Bottom));
            path.CloseAllFigures();
            g.FillPath(new SolidBrush(c1), path);

            g.FillRectangle(new SolidBrush(lampstand), new Rectangle(5, m_rectWorking.Bottom - 19, this.Width - 10, 10));
            g.FillRectangle(new SolidBrush(lampstand), new Rectangle(0, m_rectWorking.Bottom - 10, this.Width, 10));
        }

期待提供指定颜色(非闪烁时)的方法。

评论 (1)

sword_happy 创建了任务
展开全部操作日志

好多,感谢 ,后面会优化处理

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
301547 kwwwvagaa 1578919741 362628 sword happy 1578921546
C#
1
https://gitee.com/kwwwvagaa/net_winform_custom_control.git
git@gitee.com:kwwwvagaa/net_winform_custom_control.git
kwwwvagaa
net_winform_custom_control
HZHControls控件库

搜索帮助

14c37bed 8189591 565d56ea 8189591