面板图形消失。救命 [英] Panel graphics disappear. Help

查看:71
本文介绍了面板图形消失。救命的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个面板我画了一些东西..

这是我代码的一部分(你不需要阅读所有代码,我只是想要显示它的样子):

Hi,
I have a panel which i draw something..
This is a part of my code(You dont need to read all code, i just wanted to show how it looks like):

Dim g As Graphics = msjscrlist.Item(sender.tag).Controls("Powner").Controls("P").CreateGraphics
for i=0 to ......
code...
for k=0 to ......
code...
msjcount += 1
linecount = 1
If g.MeasureString(ben, New Font("tahoma", 8)).Width > msjscrlist.Item(sender.tag).Controls("Powner").Controls("P").Width - 10 Then
  linecount = Math.Ceiling(g.MeasureString(ben, New Font("tahoma", 8)).Width / msjscrlist.Item(sender.tag).Controls("Powner").Controls("P").Width - 10)
End If
If itsme = True Then
  g.FillRectangle(New SolidBrush(Color.Green), msjscrlist.Item(sender.tag).Width - g.MeasureString(ben, New Font("tahoma", 8)).Width - 20, sonalt + 8, g.MeasureString(ben, New Font("tahoma", 8)).Width + 20, linecount * 28)
  g.DrawString(ben, New Font("Tahoma", 8), Brushes.White, New Point(msjscrlist.Item(sender.tag).Width - g.MeasureString(ben, New Font("tahoma", 8)).Width - 10, sonalt + 16))
  sonalt += 8 + linecount * 28
  ben = Nothing
Else
  g.FillRectangle(New SolidBrush(Color.Teal), 0, sonalt + 8, g.MeasureString(hedef, New Font("tahoma", 8)).Width + 20, linecount * 28)
  g.DrawString(hedef, New Font("Tahoma", 8), Brushes.White, New Point(10, sonalt + 16))
  sonalt += 8 + linecount * 28
  hedef = Nothing
End If
next
code...
next





问题是;当我滚动面板时,我绘制的图形正在消失,我怎样才能使这些图形持久存在?人们说:做'onpaint'活动。但是我有一个很长的代码,不会很慢吗?



The problem is; graphics that i draw are disappearing when i scroll the panel, how can i make those graphics persistent? People say: do drawing in 'onpaint' event. But i have a long code, wouldn't it be slow?

推荐答案

但我有一个很长的代码,它会不会很慢?

嗯 - 这是你的选择:如果你想让你绘制的图形保持可见,那么你必须以持久的方式绘制它们 - 这意味着OnPaint需要参与其中。



但是......还有别的什么可以做。如果您的图形不变(或不经常更改),那么您可以绘制到图像而不是绘制Paint事件(以及每次执行该操作所需的时间),并在Panel中显示(可能通过PictureBox控件) )。这样,绘图代码执行一次,Paint事件只绘制图像的适当部分。
"But i have a long code, wouldn't it be slow?"
Well - it's your choice: If you want the graphics you draw to remain visible, then you have to draw them in a persistent way - and that means that OnPaint needs to be involved.

But...there is something else you could do. If your graphics are unchanging (or change infrequently) then instead of drawing in the Paint event (and the time it takes to do that each time) you could draw onto a Image instead, and display that in the Panel (possibly via a PictureBox control). That way, the drawing code is executed once, and the Paint event just draws the appropriate part of the image.


这篇关于面板图形消失。救命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆