狐表单元格绘制进度条 ,用于表示价格涨跌幅度

发表日期: 2022-11-18

 1.效果

image.png


2.代码

放在DrawCell事件里

'计算平均单价涨价幅度
If e.Col.Name = "平均单价" Then
    Dim rate As Decimal = 0
    If e.Row("平均单价") <> 0 AndAlso e.Row("历史采购单价") <> 0 AndAlso e.Row("平均单价") <> e.Row("历史采购单价") Then
        rate = e.Row("平均单价") / e.Row("历史采购单价") - 1
    End If 
    If rate <> 0 Then
        e.StartDraw
        If rate < 0 Then '注意绘图的最大宽高度e.Width和e.Height,要-2,防止爆出单元格
            Dim Width As Integer = (e.Width - 2) * ( - rate)
            e.Graphics.FillRectangle(Brushes.LightGreen, e.x + 1, e.y + 1, Width , e.Height - 2) 
        Else If rate > 0 AndAlso rate < 1 Then
            Dim Width As Integer = (e.Width - 2) * rate 
            e.Graphics.FillRectangle(Brushes.Tomato, e.x + 1, e.y + 1, Width , e.Height - 2)
        Else If rate >= 1 Then
            Dim Width As Integer = (e.Width - 2) * rate 
            e.Graphics.FillRectangle(Brushes.Red, e.x + 1, e.y + 1, e.Width - 2, e.Height - 2)
        End If
        e.EndDraw
    End If
End If




随便看看
商务联系QQ : 2385350359

Copyright 2016-2023 江门蓬江区华越科技公司 版权所有 | 承接软件定制开发,欢迎联系
粤ICP备19148806号-5