在drawcell中绘制条形码的时候,为了让条形码居中单元格 需要做个运算。
整段代码如下
If e.Col.Name.contains("条码") Then
If e.Row(e.col.Name ).length = 13 Then
BarCode.Code = e.Text.SubString(0,12)
'e.Graphics.DrawImage(BarCodeCtl.GetImage,e.X + 1,e.Y + 1,e.Width - 2,e.Height - 2) '图片适应单元格大小
dim startx ,imgwidth as integer
imgwidth = ?
startx = e.width/2 - imgwidth/2
e.Graphics.DrawImage(BarCode.GetImage,e.X + startx , e.Y + 1)
'如果觉得适应单元格大小时图片比较模糊就用这一句
e.Text = ""
End If
End If
如何获得这个imgwidth呢?

此主题相关图片如下:2012-09-18_221034.jpg