none
VB: form border adjustment to backcolor: problem with the borderlines

    Question

  • hi, i'm trying to adjust form size by usage of "Me.TransparencyKey = BackColor"

    and unfortunately for me it creates questions: part of the border is not transparent, how it can be fixed by VB code?remained nontransparent space

    Sunday, March 19, 2017 12:13 PM

All replies

  •  Well,  i wont say that i understand exactly what you are saying the problem is but,  you do understand that setting the TransparencyKey of the form will only make anything of that one color transparent.  Anything that is even a slightly different color will be visible.

    If you say it can`t be done then i`ll try it

    Sunday, March 19, 2017 1:14 PM
  • and how it can be solved?
    Sunday, March 19, 2017 1:29 PM
  • Hi,

    what do you mean? Do you want to blend the forms outline with the background? So that the AntiAlias-Pixels of the outline dont "jump into your eyes"?

    Regards,

      Thorsten

    Sunday, March 19, 2017 1:41 PM
  • Hi,

    what do you mean? Do you want to blend the forms outline with the background? So that the AntiAlias-Pixels of the outline dont "jump into your eyes"?

    Regards,

      Thorsten

    ... if so, there's a clean solution to this:

    https://www.codeproject.com/Articles/1822/Per-Pixel-Alpha-Blend-in-C

    and

    https://www.codeproject.com/Articles/20758/Alpha-Blended-Windows-Forms

    there's also an easy workaround for this, if you do not move the form. then you could copy the background (with Graphics.CopyFromScreen) *before* your form is shown and blend it with your form(s), but I'd prefer the first solution.

    Regards,

      Thorsten

    Sunday, March 19, 2017 1:46 PM
  • many thanks for advise, it looks that the best way to paint/substitute the colors by a color(e.g. black) and use it in the form backcolor option, please inform if it has better solution
    Sunday, March 19, 2017 2:18 PM
  • many thanks for advise, it looks that the best way to paint/substitute the colors by a color(e.g. black) and use it in the form backcolor option, please inform if it has better solution

    Instead of using a transparent background color you can use transparent images which will shade the edge differently.

    You can also draw each image yourself with a range of transparent color, that way you can do say all shades of black and gray <55 (see code) or whatever works for your colors. When you draw the image use g.smoothingmode = none and then you wont get the edge blending.

           'draw pic with transparent color
            Dim attribs As New System.Drawing.Imaging.ImageAttributes
            attribs.SetColorKey(Color.FromArgb(0, 0, 0), Color.FromArgb(55, 55, 55))
            Dim dst As New Rectangle(0, 0, ClientSize.Width, ClientSize.Height)
            e.Graphics.DrawImage(bmp, dst, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attribs)
    

    Sunday, March 19, 2017 2:31 PM
  • Your image is probably a JPEG.  Use a PNG file instead.  The compression of a JPEG makes some of the pixels the wrong color for the transparency key being used.  Also, you can't have semi-transparent pixels at all since there is only a single transparency key color in effect.  You'll have to clean up the source image until it is compatible with the transparency key you are using.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Sunday, March 19, 2017 2:36 PM
    Moderator