An object-oriented programming language developed by Microsoft that can be used in .NET.
Hello @Antony ,
After reading through the sample you linked, it looks like the current behavior happens because the image is loaded once as a fixed HBITMAP and then sent directly to the layered window:
Dim hBitmap As IntPtr = TransparentControl1.LoadImage("Hulk.png", System.Drawing.Color.FromArgb(0))
TransparentControl1.SetBitmap(hBitmap)
So if the TransparentControl is resized later, only the control bounds change. The image itself does not seem to be recalculated or redrawn against the new client area, which is why it can appear cropped instead of resized.
As a workaround, I tried refactoring the sample a little so the control keeps the original image in memory, adds layout-style modes, and redraws the image when the control size changes. In my test, I focused on the three behaviors you mentioned: Zoom, Stretch, and Scale.
Public Enum TransparentImageLayout
Normal = 0
Stretch = 1
Zoom = 2
Scale = 3
End Enum
I also trigger a redraw whenever the control is resized:
Protected Overrides Sub OnResize(e As EventArgs)
MyBase.OnResize(e)
RenderCurrentImage()
End Sub
For manual scaling, I tested logic like this from the form:
Dim newWidth As Integer = CInt(m_originalControlSize.Width * value)
Dim newHeight As Integer = CInt(m_originalControlSize.Height * value)
TransparentControl1.Size = New Size(newWidth, newHeight)
TransparentControl1.ScaleFactor = value
TransparentControl1.ImageLayoutMode = TransparentControl.TransparentImageLayout.Scale
This seems to behave closer to what you described. I would not say this is the definitive fix, but it may be a useful workaround if you want TransparentControl to behave more like a PictureBox with layout-style options.
Also, I attached a few screenshots from my test project showing zoom, stretch, and scale behavior in case that helps illustrate the approach more clearly.
Zooming
Stretching
Scaling
Hope this clarifies your question. If you found my answer helpful, you could follow this guide to give feedback.
Thank you.