Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:11:39+00:00 2026-06-08T19:11:39+00:00

I got following code to load a PNG with alpha channel on to a

  • 0

I got following code to load a PNG with alpha channel on to a form and reshape a form to match alpha channel.

Public Function applyAlphaForm(ByVal f As Form, ByVal bitmap As Bitmap, Optional ByVal opacity As Byte = 255) As Boolean
    f.FormBorderStyle = FormBorderStyle.None
    Dim style As Long
    style = Win32.GetWindowLong(f.Handle, Win32.GWL_EXSTYLE)
    If Not (style And Win32.WS_EX_LAYERED = Win32.WS_EX_LAYERED) Then
        style = style Or Win32.WS_EX_LAYERED
        Win32.SetWindowLong(f.Handle, Win32.GWL_EXSTYLE, style)
    End If
    Return SetBitmap(f, bitmap, opacity)
End Function

Public Function SetBitmap(ByVal f As Form, ByVal bitmap As Bitmap, ByVal opacity As Byte) As Boolean
    f.Height = bitmap.Height
    f.Width = bitmap.Width
    If bitmap.PixelFormat <> PixelFormat.Format32bppArgb Then
        f.BackgroundImage = bitmap
        f.TransparencyKey = bitmap.GetPixel(0, 0)
        Return True
    End If

    Dim screenDC As IntPtr = Win32.GetDC(IntPtr.Zero)
    Dim memDC As IntPtr = Win32.CreateCompatibleDC(screenDC)
    Dim hBitmap As IntPtr = IntPtr.Zero
    Dim oldBitmap As IntPtr = IntPtr.Zero

    Try
        hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)) 'grab a GDI handle from this GDI+ bitmap
        oldBitmap = Win32.SelectObject(memDC, hBitmap)

        Dim size As Win32.Size = New Win32.Size(bitmap.Width, bitmap.Height)
        Dim pointSource As Win32.Point = New Win32.Point(0, 0)
        Dim topPos As Win32.Point = New Win32.Point(f.Left, f.Top)
        Dim blend As Win32.BLENDFUNCTION = New Win32.BLENDFUNCTION()
        blend.BlendOp = Win32.AC_SRC_OVER
        blend.BlendFlags = 0
        blend.SourceConstantAlpha = opacity
        blend.AlphaFormat = Win32.AC_SRC_ALPHA

        Win32.UpdateLayeredWindow(f.Handle, screenDC, topPos, size, memDC, pointSource, 0, blend, Win32.ULW_ALPHA)

    Catch ex As Exception
    Finally
        Win32.ReleaseDC(IntPtr.Zero, screenDC)
        If hBitmap <> IntPtr.Zero Then
            Win32.SelectObject(memDC, oldBitmap)
            Win32.DeleteObject(hBitmap)
        End If
        Win32.DeleteDC(memDC)
    End Try
    Return True
End Function

Nice and easy but if I put some control (button, text box …) on the form, they will disappear. I guest that UpdateLayeredWindow will paint over the form hDC so we can’t see anything behind it. So how to draw some form control on the form? I’ve try to loop through all control and render to png bitmap before calling api but that will be static image.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:11:40+00:00Added an answer on June 8, 2026 at 7:11 pm

    So I guest I have to create two from, a background form alpha transparent and a foreground form with control on it. The control form will only display the area of control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following code: <script type=text/javascript> $(function(){ $(#AddMaps).submit(function(){ var $form = $('#AddMaps'); $.ajax({
All, I've got the following code to load a page in Fancybox: $(#display_songs).fancybox({ 'href'
I got the following code : <script type=text/javascript> jQuery(document).ready(function(){ var Opened = false; jQuery('.expend-schedule').click(function(e){
I got the following code: public class Alarm:IDisposable { MemoryStream _tmp; readonly XmlDocument _doc;
I've got the following code in my headers to load a font from Google's
I'm using the following code to load in content: <script type=text/javascript> jQuery.noConflict(); jQuery(document).ready(function(){ jQuery('.content-div').load(all-events.html);
I have got the following code in a button on a form, but I
All, I've got the following code to which is basically a function that loads
I am using following code to load public shared images from google drive to
I've got the following code: $(#another).click(function() { $('#another').replaceWith('<a id=another class=btn btn-primary btn-mini disabled><i class=icon-refresh

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.