Product : Engine, Version : 5.1.1.1041, ArticleID : 41024253

HowTo : How can I make a cmdImage that way that the image is visible while choosing the insertion point ?

Article41024253
TypeHowTo
ProductEngine
Version5.1.1.1041
Date Added6/26/2006
Submitted byGregory D. Heil
Keywords

Subject

How can I make a cmdImage that way that the image is visible while choosing the insertion point ?

Summary

How can I make a cmdImage that way that the image is visible while choosing the insertion point ?
- The user should select an image they wish to insert into the drawing.  Once the image has been chosen, it should be displayed next to the mouse cursor while the user is selecting the spot to insert the image.  Once the left mouse button is clicked down, the Image should be placed in that location.
 
The problem is, when I do the command "ScreenRender.DrawImage()" it will leave a trail of the image as you draw the mouse cursor around, as if there is an issue with the screen refreshing or something.  Because, when you zoom in and out, the trail will disappear, but until the screen somehow gets re-drawn the image trail will stay there.
 
The following is an example of the code:

void imageSelected(string picturePath)

{     

    DrawImage = true;  

    vd.CommandAction.CmdImage(picturePath, "USER");

    DrawImage = false;

}

 

if (e.action == VdConstCmdActions.CMDGETPOINT && DrawImage)

{

   object picture = vd.Utility.GetFilePicture(Loc);

   vd.ScreenRender.DrawImage(picture, e.currentPoint, 1, 0);           

}

Solution

In vdImage entity the XOR (and the Render) is not working like in vdLine, vdArc etc objects. So you code should be changed to something like :
public string LocImg = @"c:\windows\Prairie Wind.bmp";
public bool DrawImage = false;
public string imgHandle = "";

private
void button1_Click(object sender, EventArgs e)
{
    VD.CommandAction.Undo(
"BEGIN");
    VDProLib5.
vdImage img = VD.ActiveDocument.Entities.AddImage(LocImg, new object[] { 0, 0, 0 }, 1);
    imgHandle = img.Handle;
    DrawImage =
true;
    object loc = VD.Utility.GetPoint();
    DrawImage =
false;
    if (loc==null) {
        img.Deleted =
true;
    }
else {
        img.InsertionPoint = loc;
    }
    img.Invalidate();
    VD.CommandAction.Undo(
"END");
}

private void Form1_Load(object sender, EventArgs e)
{ VD.UndoMode =
true; }

private void VD_CommandActionDraw(object sender, AxVDProLib5._DVdrawEvents_CommandActionDrawEvent e)
{
    if ((e.action == VDProLib5.VdConstCmdActions.CMDGETPOINT) && (DrawImage)){
       
VDProLib5.vdImage img = VD.ActiveDocument.GetFromHandle(imgHandle) as VDProLib5.vdImage;
        img.Invalidate();
        img.InsertionPoint = e.currentPoint.Value;
        e.render.DrawEntity(img); }
}