Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

- How to show AddShape object over Image control?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 31 Mar 2006 21:16 GMT
I am having a problem displaying a shape object over/above an image control.

What I am trying to do is pretty simple - draw a circle on Image_click over
the clicked area (see the code below)

The problem is that the newly added shape object appears behind the image
(and cannot be seen) even though its ZOrder property is set to
msoBringToFront.

Ohh, and by the way could someone suggest why the circles get drawn with an
offset from the mouse pointer. Am I missing something here?

Private Type TPoint
  X As Long
  Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As TPoint)
As Boolean

Private Sub Image1_Click()
 Dim point As TPoint
   If (GetCursorPos(point)) Then
    ThisDocument.Shapes.AddShape(msoShapeOval,point.x,point.y,10,10).Select
    Selection.ShapeRange.ZOrder msoBringToFront
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 2.25
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.RGB = RGB(255, 0, 0)
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
  End If
End Sub
Jean-Guy Marcil - 03 Apr 2006 17:00 GMT
Dan was telling us:
Dan nous racontait que :

> I am having a problem displaying a shape object over/above an image
> control.
[quoted text clipped - 4 lines]
> image (and cannot be seen) even though its ZOrder property is set to
> msoBringToFront.

I believe that the reason is that ACtiveX controls are always on top when
you exit design mode.
Which makes sense, if a control was hidden by a shape, the user could not
use it.
But I am no expert with ActiveX control as I never use them. They very often
end up creating problem for users.

You could use a MACROBUTTON with an image (inline) instead of a text invite:

   {MACROBUTTON OnClickMe InLine_Image }

Also, you have to set the Wrap property of the drawn shape, otherwise it
will have the default setting (Square I believe)

> Ohh, and by the way could someone suggest why the circles get drawn
> with an offset from the mouse pointer. Am I missing something here?

Yes!
GetCursorPos returns the mouse pointer position in relation to the screen,
not the printed page in the Word document in the Word window.
To get what you want, you would have to get the screen resolution, get the
Word window position, the document window position, do some maths to get the
actual pointer position in relation to the document... very complicated,
and, unless I am missing something simple, very difficult to achieve.

But, not all is lost!
You can get the Word cursor position very easily, and, if you make the
MACROBUTTON image small enough, the circle will be drawn almost on top of
the image (Almost because, in this case, Word returns the position of the
cursor in relation to the the MACROBUTTON field (left edge) and top edge,
not the place where the user clicks on the image inside the MACROBUTTON
field.)

So, try this modified code (Note that I use With/End With blocks, it makes
the code easier to read , easier to maintain and it executes a bit faster)

'_______________________________________
Private Type TPoint
  X As Long
  Y As Long
End Type

'_______________________________________
Private Declare Function GetCaretPos Lib "user32.dll" _
   (lpPoint As TPoint) As Boolean

'_______________________________________
Sub OnClickMe()

Dim point As TPoint
Dim MyShape As Shape

With Selection
   point.X = .Information(wdHorizontalPositionRelativeToPage)
   point.Y = .Information(wdVerticalPositionRelativeToPage)
End With

   Set MyShape = ActiveDocument.Shapes _
       .AddShape(msoShapeOval, point.X, _
       point.Y, 10, 10)
   With MyShape
       .ZOrder msoBringToFront
       With .Fill
           .Visible = msoFalse
           .Solid
           .Transparency = 0#
       End With
       With .Line
           .Weight = 2.25
           .DashStyle = msoLineSolid
           .Style = msoLineSingle
           .Transparency = 0#
           .Visible = msoTrue
           .ForeColor.RGB = RGB(255, 0, 0)
           .BackColor.RGB = RGB(255, 255, 255)
       End With
       .WrapFormat.Type = wdWrapNone
   End With

End Sub

'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.