• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

How to write code in MFC to show that label of a circle can move with the moving of the circle?

On a map, I created a circle zone with a label, ex. Zone 1, and set the lable to be visible in my MFC code. There is a feature for this circle that it can be moved to anywhere on the map. But the problem is that the label with the circle does not move with the circle.
  • 2
1 Solution
You know the coordinates of the circle before and after the move.  That gives you a delta-x and delta-y you can apply to the .Top and .Left of the label.
Note that if the circle is moved to a position such that the label goes off the visible part of the window, you may want to add some code to adjust the label's position so that it stays visible.  It's a bit of busy-work code, but quite user friendly.

It would be something like this:
deltaX - circle's horizontal change
deltaY - circle's vertical change

if ((label.left+deltax)<0) label.left=0;
if ((label.left+label.width+deltax)>window.width) label.left=window.width-label.width;
if ((label.top+deltay)<0) label.top=0;
if ((label.top+label.height+deltay)>window.height) label.top=window.height-label.height;

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now