Monday, 15 March 2010

c# - Border on label when using transparency key -



c# - Border on label when using transparency key -

i have winform (with transparency key) create transparent. when add together label, "fushia" border around label. aware because of there no "set" background control. there way remove "border".

the form set background fuchsia (transparency key fuchsia) , label set transparent. tried painting panel same results.

what missing?

how looks, http://oi62.tinypic.com/2wq9z7c.jpg

public class clabel : label { protected override createparams createparams { { createparams parms = base.createparams; parms.exstyle |= 0x20; homecoming parms; } } public clabel() { this.setstyle(controlstyles.opaque, true); this.setstyle(controlstyles.optimizeddoublebuffer, false); } protected override void onpaintbackground(painteventargs e) { // null } graphicspath getstringpath(rectanglef rect, stringformat format) { graphicspath path = new graphicspath(); path.addstring(this.text, this.font.fontfamily, (int)font.style, this.font.size, rect, format); homecoming path; } protected override void onpaint(painteventargs e) { rectanglef rect = this.clientrectangle; font font = this.font; stringformat format = stringformat.genericdefault; using (graphicspath path = getstringpath(rect, format)) { smoothingmode sm = e.graphics.smoothingmode; e.graphics.smoothingmode = smoothingmode.antialias; brush b = new solidbrush(color.white); e.graphics.fillpath(b, path); e.graphics.drawpath(pens.black, path); b.dispose(); } } } public partial class dy : form { protected override createparams createparams { { createparams cp = base.createparams; cp.exstyle |= 0x02000000; cp.exstyle |= 0x80; homecoming cp; } } public dy() { initializecomponent(); setstyle(controlstyles.userpaint, true); setstyle(controlstyles.allpaintinginwmpaint, true); setstyle(controlstyles.doublebuffer, true); setstyle(controlstyles.userpaint, true); setstyle(controlstyles.supportstransparentbackcolor, true); this.startposition = formstartposition.manual; // here add together label clabel p = new clabel{ location = new point(768, 702), text = "25", autosize = false, size = new size(50,50), textalign = contentalignment.middlecenter, backcolor = color.transparent, forecolor = color.white, borderstyle = borderstyle.none, font = new font("segoe ui", 30, fontstyle.bold) }; } }

looks anti-aliasing artefacts.

you can seek change

e.graphics.textrenderinghint = system.drawing.text.textrenderinghint.antialias;

to

e.graphics.textrenderinghint = system.drawing.text.textrenderinghint.singlebitperpixel;

or can set anti-aliasing off:

e.graphics.smoothingmode = system.drawing.drawing2d.smoothingmode.none;

edit: have moved out of comments, may help folks:

here little extra on aa-artefacts..

aa create pixels interpolate , result in pixels miss transparency key color.

obviously go away if no aa used; if 1 needs smoothing little trick may help improve result:

usually transparencykey accomplished crass color fuchsia or hotpink. these used, they're not cutting holes, when shine through semitransparent aa pixel obnoxious. if use less irritating color effect can unobtrusive.

you need create sure not using elsewhere. pick color color.fromargb(255, r,g,b) picking 3 unique values won't utilize elsewhere blend in both foreground , more of import background. low saturation , depending on graphics, medium brightness help..

black or neutral grayness not choices if blend well, because used often. picking e.g. black argb(255, 7, 11, 5) has chance blend without beingness used in graphics , cutting holes in output.

the best result when can utilize somthing close background color. if can't forsee trick more not fail, though..

c# winforms

No comments:

Post a Comment