Hi Michael,
I've done this recently with my new free program (including source)
WTR - Web The Ripper 2. I'll highlight what I done before giving you the
link.
*Embed the image as a resource but use a PNG file if you want it alpha
blended into the background colour. I chose 15% alpha.
*In the Paint event of the panel control in the base form, do the
following,
~~~
Static pBmpBackdrop As Bitmap = getBackdrop(panStep.Width, panStep.Height,
panStep.BackColor)
Call e.Graphics.DrawImageUnscaled(pBmpBackdrop, 0, 0)
~~~
Private Function getBackdrop(ByVal iWidth As Integer, ByVal iHeight As
Integer, ByVal iBackColour As Color) As Bitmap
Dim pBmpAlpha As New Bitmap(iWidth, iHeight)
Dim pImgBack As Image =
getImageFromResource("fullnamespace.backdrop.png")
Dim pGraAlpha As Graphics = Graphics.FromImage(pBmpAlpha)
Call pGraAlpha.Clear(iBackColour)
Call pGraAlpha.DrawImage(pImgBack, New Rectangle(CInt((pBmpAlpha.Width
/ 2) - (pImgBack.Width / 2)), CInt((pBmpAlpha.Height / 2) -
(pImgBack.Height / 2)), pImgBack.Width, pImgBack.Height), 0, 0,
pImgBack.Width, pImgBack.Height, GraphicsUnit.Pixel)
Call pGraAlpha.Dispose()
Return (pBmpAlpha)
End Function
Public Shared Function getImageFromResource(ByVal iKey As String) As Image
Dim pAssAssembly As [Assembly] = [Assembly].GetExecutingAssembly
Dim pStmInput As Stream = pAssAssembly.GetManifestResourceStream(iKey)
Dim pImgImage As Image = Image.FromStream(pStmInput, False)
Call pStmInput.Close()
Return (pImgImage)
End Function
~~~
Then compile your application and run it. You should see a picture
painted into the middle of the panel. One thing you will also want to do
is make the back colour of any labels, check boxes and radio buttons
Transparent. But *dont* use the web transparent, this had strange effects
for me. Instead you can call the following method from the derived class
(put it in the base class) upon loading it.
Protected Sub makeControlsTransparent()
Dim pCtlCurControl As Control
For Each pCtlCurControl In panStep.Controls
If (TypeOf (pCtlCurControl) Is Label) Then
CType(pCtlCurControl, Label).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is CheckBox) Then
CType(pCtlCurControl, CheckBox).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is RadioButton) Then
CType(pCtlCurControl, RadioButton).BackColor =
System.Drawing.Color.Transparent
End If
Next
End Sub
For a full working application as an example with very readable code,
goto my home page
http://www.members.lycos.co.uk/nickpatemanpwp/
^Click "My Own Software" > "WTR - Web The Ripper 2".
Nick.
Michael Turner said:
Hi Guys
I have several images that will be used over and over again on different
forms in the same place, I have decided to create a control to save
space/time in development, I have create a control which inherits the
panel and added three panel control which host the 3 background images
( one to the left the other to the right and one to fill the gap) now
with this control textboxes will be placed on these controls once they
are added to the intended form however when you get to this stage they
seem to dissapear when I move them to the front the repear they come to
the from but have inherited the background colour of the main form and
not of my panels in my control any ideas on how to get round this.
Thanks Mike.