开发者

C# draw points in resizable picture

I'm writing simple C# application for viewing maps. Maps are JPG images with size about 1000x1000 or something like that and can be resized proportionally. I have a set of points coordinats (x,y) and names. Viewer is a Windows Form Application with control Panel and PictureBox within. PictureBox has attribute SizeBox=AutoSize. I use such approach for placing points onto the map (PictureBox).

Graphics g = Graphics.FromHwnd(pictureBox.Handle);
SolidBrush redBrush = new SolidBrush(Color.Red);
g.FillEllipse(redBrush, x, y, 7, 7);

After scrolling or resizing the form all points disapeard. If I draw points开发者_运维百科 on Paint event I have big problems with performance. How to solve this problem?


For better performance, try to draw only what is currently visible. Best practice would be to drop the PictureBox and use only two Scrollbars (or something else that can scroll like a PictureBox) and draw the map and the points only for the small part that is visible. Before doing that, try to draw the points into the PictureBox whenever it is resized or scrolled, and check wich points are inside the visible area.

Added: Maybe it would be good enough if you draw your elements into a copy of the jpg and put that into the PictureBox?


You should be able to hook event handlers to the various points of change for your PictureBox (you mentioned scrolling and resizing). Then you can put you drawing code in a method called from these event handlers.


WPF would probably be a better choice for this. It's hardware accelerated, and will perform all clipping and zooming transformations for you (you just set the appropriate properties). And you should be able to keep track of the POI using WPF elements as well, instead of having to draw them yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜