2016-11-20 24 views
0

我已經設置了100個圖片箱並使用了拉繩添加了文本元素。我使用循環來更新文本,同時我設置了picturebox背景色。循環後,並不是所有的文字都顯示出來。有些是空白的,有些是顯示的,但是是間歇的圖片箱文字並不總是顯示

Private Sub LoadStepPatternFlash() 

    intBank = intSequenceNumber * 100 

    For intCounter = 0 To 99 

     Dim g As Graphics = PicPixel(intCounter).CreateGraphics() 
     PicPixel(intCounter).BackColor = Color.FromArgb(intPatternColorsRed(strhexPixelHexValue(intCounter + intBank)), intPatternColorsGreen(strhexPixelHexValue(intCounter + intBank)), intPatternColorsBlue(strhexPixelHexValue(intCounter + intBank))) 

     g.DrawString(strhexPixelHexValue(intCounter + intBank), New Font("Arial", 10), Brushes.White, 1, 1) 
     '  PicPixel(intCounter).Refresh() 
    Next 

End Sub 

如果我在endsub處放一個斷點,那麼F5(繼續)文本每次都顯示正常。任何想法?

回答

0

找到了一個修復程序,我不繪製的圖片框,但我創建一個位圖,並在位圖上繪製,然後發佈位圖圖像到圖片框。所有問題都得到了解決。

Private Sub LoadStepPatternFlash() 


    Dim NG As Graphics 
    Dim Color_Background As Color 
    Dim Brush_Background As Brush 

    Dim LastColorIndicator As Color 
    Dim LastColorBrush As Brush 

    Dim bmp As Bitmap 


    intBank = intSequenceNumber * 100 

    If intSequenceNumber > 0 Then 
     intLastBank = (intSequenceNumber - 1) * 100 
    End If 


    For intCounter = 0 To 99 

     Dim Pen As Pen = New Pen(Color.White) 

     bmp = New Bitmap(Pb_Seg1.Image)  '//Image is white bitmap 
     NG = Graphics.FromImage(bmp) 

     Color_Background = Color.FromArgb(intPatternColorsRed(strhexPixelHexValue(intCounter + intBank)), intPatternColorsGreen(strhexPixelHexValue(intCounter + intBank)), intPatternColorsBlue(strhexPixelHexValue(intCounter + intBank))) 
     Brush_Background = New SolidBrush(Color_Background) 
     NG.FillRectangle(Brush_Background, 0, 0, 30, 30) 

     LastColorIndicator = Color.FromArgb(intPatternColorsRed(strhexPixelHexValue(intCounter + intLastBank)), intPatternColorsGreen(strhexPixelHexValue(intCounter + intLastBank)), intPatternColorsBlue(strhexPixelHexValue(intCounter + intLastBank))) 
     LastColorBrush = New SolidBrush(LastColorIndicator) 
     NG.FillRectangle(LastColorBrush, 0, 0, 12, 12) 
     NG.DrawRectangle(Pen, 0, 0, 12, 12) 
     Pen.Dispose() 

     If ShowPixelNumber Then 
      NG.DrawString((intCounter + 1), New Font("Arial", 8), Brushes.White, 20, 20) 

     End If 

     If ShowColorNumber Then 
      NG.DrawString(strhexPixelHexValue(intCounter + intBank), New Font("Arial", 8), Brushes.White, 1, 1) 
     End If 

     PicPixel(intCounter).Image = bmp 

    Next 

End Sub