如何将对象设置在前景 [英] How to set the object at foreground

查看:122
本文介绍了如何将对象设置在前景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在将对象设置为前景时遇到问题.我已经问过这个问题,我的答案是使用BringToFront(),我已经尝试过.我无法解决它.问题是我有用于绘制椭圆和矩形的单独类.(类似于在矩形上绘制椭圆).更改rect shud的颜色不会隐藏椭圆.对此我还需要任何其他建议.

在此先感谢,
Shiva ..

Hi,

I have a problem regarding setting the object at foreground.I''ve already asked this question,the answer i got is to use BringToFront(),I''ve tried with that.I am unable to solve it.The thing is i have seperate classes for drawing ellipse and rectangle.(drawing like ellipse on rectangle).Changing the color of rect shud not hide ellipse.I need any other suggestions on this.

Thanking in advance,
Shiva..

推荐答案

您可以将对象保存在列表中
(例如,作为documents属性).

所以-如果您在图纸上进行迭代-
您从后面的对象走到了最上面的对象...:)
You could hold your objects in a list
(for example as a documents property).

So - if you iterate them at the drawing -
you walk from the back- to the top-objects... :)


John Simmons在上一个回答中的关键词是:如果它确实是一个对象而不仅仅是GDI图形.显然,从Windows的角度来看,您拥有的不是对象. (这与面向对象的编程对象不同.)从这个意义上说,这不是对象(窗口/控件),因此就Windows而言,没有前景或背景之类的东西.相反,这完全取决于您.它将按照您编写代码的方式工作.

现在,由于您正在执行Windows程序并在工作区中进行绘制,因此大概会遵循在窗口上绘制的通常做法,只是对绘制消息的响应(OnDraw()).因此,当事件指示用户想要更改矩形的颜色时,您无需在窗口上绘制任何内容.您更新指示新颜色的状态,并使包含矩形的窗口区域无效.而已.稍后将发生一次绘画事件,然后将调用OnDraw.在那里,您编写的代码会根据当前状态(包括矩形和椭圆形)重新绘制无效区域.只要确保您的代码在椭圆之前重绘了矩形即可.

现在,在矩形和椭圆之间的重叠区域中将出现一些闪烁.为了解决这个问题,您将不得不进入双重缓冲.现在不用担心.首先了解有关在Windows中显示内容的工作原理.以后再看.
The key phrase in the previous answer to you by John Simmons is: If it''s truly an object and not just a GDI drawing. Evidently what you have is not an object from the perspective of windows. (That is different than being an object oriented programming object.) Since this is not an object (window/control) in this sense, there is no such thing as foreground or background for it as far as windows is concerned. Instead, this is all up to you. It will work the way you code it to work.

Now since you are doing a windows program and drawing in the client area, you will presumably be following the usual practice of drawing on the window only is response to paint messages ( OnDraw() ). So when an event indicates the user wants to change the color of the rectangle, you don''t paint anything on window. You update your state indicating the new color and invalidate the area of the window that contains the rectangle. That''s it. Later there will be a paint event and OnDraw will be called. There the code you wrote repaints the invalid region based on your current state, including the rectangle and the ellipse. Just be sure that your code redraws the rectangle before the ellipse.

Now this will have some flicker in the area of overlap between the rectangle and ellipse. To deal with that, you would have to get into double buffering. Don''t worry about that now. First get the basics of how displaying stuff in Windows works. Get fancy later.


这篇关于如何将对象设置在前景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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