Is there a way to make GoIconicNode transparent, like setting its alpha value?
The GoIconicNode is initialized like that:
iconicNode.Initialize(imageList, 1, “Bla”);
Thanks Alon.
I don’t know how to do it with an imagelist directly. You can use a .PNG file that has transparency value.
or, you can use this class as your GoImage (which can you use with ImageList)
[Serializable]
class ImageOpacity : GoImage {
public ImageOpacity() {
myOpacity = 1.0f;
}
public override void Paint(Graphics g, GoView view) {
if (myOpacity == 1.0f) {
base.Paint(g, view);
return;
}
RectangleF rect = this.Bounds;
Image img = this.Image;
int idx = this.Index;
if (img == null && idx >= 0) {
System.Windows.Forms.ImageList ilist = view.ImageList;
if (ilist != null && idx < ilist.Images.Count) {
img = ilist.Images[idx];
}
}
if (img != null) {
try {
if (this.Shadowed) {
SizeF offset = GetShadowOffset(view);
ColorMatrix cm = new ColorMatrix();
cm.Matrix00 = 0;
cm.Matrix11 = 0;
cm.Matrix22 = 0;
SolidBrush brush = GetShadowBrush(view) as SolidBrush;
if (brush != null) {
Color color = brush.Color;
cm.Matrix30 = color.R / 255.0f;
cm.Matrix31 = color.G / 255.0f;
cm.Matrix32 = color.B / 255.0f;
cm.Matrix33 = color.A / 255.0f;
}
else {
cm.Matrix30 = 0.5f;
cm.Matrix31 = 0.5f;
cm.Matrix32 = 0.5f;
cm.Matrix33 = 0.5f;
}
ImageAttributes im = new ImageAttributes();
im.SetColorMatrix(cm);
g.DrawImage(img, new Rectangle((int)(rect.X + offset.Width), (int)(rect.Y + offset.Height), (int)rect.Width, (int)rect.Height),
0, 0, img.Size.Width, img.Size.Height, GraphicsUnit.Pixel, im);
}
ColorMatrix cmo = new ColorMatrix(); // for opacity
cmo.Matrix33 = myOpacity;
ImageAttributes iaPic = new ImageAttributes();
iaPic.SetColorMatrix(cmo, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(img, new Rectangle((int)(rect.X), (int)(rect.Y), (int)rect.Width, (int)rect.Height),
0, 0, img.Size.Width, img.Size.Height, GraphicsUnit.Pixel, iaPic);
}
catch (Exception ex) {
if (this.ThrowsExceptions)
throw;
}
}
}
[Category(“Appearance”), DefaultValue(true)]
[Description(“Whether any parts of the document at negative coordinates can be seen or scrolled to.”)]
public virtual float Opacity {
get { return myOpacity; }
set {
float old = myOpacity;
if (old != value) {
myOpacity = value;
Changed(ChangedOpacity, 0, old, NullRect, 0, value, NullRect);
}
}
}
public override void ChangeValue(GoChangedEventArgs e, bool undo) {
switch (e.SubHint) {
case ChangedOpacity:
this.Opacity = (float)e.GetValue(undo);
return;
default:
base.ChangeValue(e, undo);
return;
}
}
private float myOpacity;
public const int ChangedOpacity = ChangedImage + 99;
}
which you can use like this:
ImageOpacity imgTransTest2 = new ImageOpacity();
imgTransTest2.Name = “graphic.png”;
imgTransTest2.Opacity = .5f;
GoIconicNode trnNode = new GoIconicNode();
trnNode.Initialize(null, null, “using ImageOpacity”);
trnNode.Icon = imgTransTest2;
trnNode.Location = new PointF(300, 500);
doc.Add(trnNode);
Or… to use an ImageList, you could override
protected virtual GoObject CreateIcon(System.Windows.Forms.ImageList imglist, int imgindex)
in GoIconicNode and create an ImageOpacity instead of a GoImage. (See the API help file for more on the CreateIcon.)