70002184 Fast highlight of hatched areas

Article 70002184
Type HowTo
Product Engine
Version 9
Date Added 3/28/2022 12:00:00 AM
Fixed 10 (3/28/2022 12:00:00 AM)
Submitted by Mike Kruse

Summary

I like to highlight with a different color some hatched areas when the mouse is over them. Invalidate is not working as expected. How can I do it?

Solution

You can “highlight” such figures using ActionDraw event. So in an empty new C# project add a vdFramedControl and a code like :

vdDocument doc;
private void Form1_Load(object sender, EventArgs e)
{
    doc = vdFramedControl1.BaseControl.ActiveDocument;
    doc.OnActionDraw += Doc_OnActionDraw;  // use the onActionDraw event
    doc.FreezeEntityDrawEvents.Push(false);
    doc.Open(@"C:\test\PixelProblem.vdml");  // the drawing you sent me
}
 
private void Doc_OnActionDraw(object sender, object action, bool isHideMode, ref bool cancel)
{
    BaseAction baction = action as BaseAction;
    vdFigure fig = baction.MouseArgs.MouseOverEntity as vdFigure;
    DrawHatchedFigure(fig, baction.Render);
}
void DrawHatchedFigure(vdFigure fig, vdRender render)
{
    if (fig == null) return;
    IvdHatchFigure hfig = fig as IvdHatchFigure;
    if (hfig == null || hfig.HatchProperties == null || hfig.HatchProperties.FillMode == VectorDraw.Professional.Constants.VdConstFill.VdFillModeNone) return; // check here the figure, if is valid for this kind of highlight
    Color existing = hfig.HatchProperties.FillColor.SystemColor;
    Color cHighlight = Color.FromArgb(255,0,0); //red color
    render.LockPenStyle = new vdGdiPenStyle(cHighlight, 127); // with alpha blending
    fig.Draw(render);
    render.LockPenStyle = null;
}
This code doesn’t need any redraw or invalidate calls.

Send comments on this topic.