lets see how to achieve this,first choose an image(better to select *.png or *.gif with transparent background) which you want to use as your form template,you can do this by selecting BackgorundImage in form properties or you can use me.BackgroundImage and remember to add it as a resource file not a local file.once your image is imported you have to set it's layout by
BackgroundImageLayout=None or me.BackgroundImageLayout=ImageLayout.None
and change the form size to cover the image completely,something like
we are allmost done just have to hide the original form which holds our image,this is a two step process
1.) Hide the form border.
2.) Make transparent the form background.
first step is easy just go to form properties and set
FormBorderStyle=None or me.FormBorderStyle=Windows.Forms.FormBorderStyle.None
however when you make your form border-less you can't move it,So we have to add some extra code here to avoid that problem.Copy this code anywhere in your form coding body.
#Region " ClientAreaMove Handling "now your form can move even without a border (don't ask me how this code works cause i don't completely understand either,and all credit goes to the original coder)
Const WM_NCHITTEST As Integer = &H84
Const HTCLIENT As Integer = &H1
Const HTCAPTION As Integer = &H2
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_NCHITTEST
MyBase.WndProc(m)
If m.Result = HTCLIENT Then m.Result = HTCAPTION
'If m.Result.ToInt32 = HTCLIENT Then m.Result = IntPtr.op_Explicit(HTCAPTION) 'Try this in VS.NET 2002/2003 if the latter line of code doesn't do it... thx to Suhas for the tip.
Case Else
'Make sure you pass unhandled messages back to the default message handler.
MyBase.WndProc(m)
End Select
End Sub
#End Region
Second step is pretty easy you just have to set form backcolor to transparent however you can't set
BackColor=Transperant or Me.BackColor = Color.Transparentbecause this is not supported by VB.NET.
so again need to do a little trick here,go to form properties and set BackColor to anycolor which is rarely used and ensure you are not going to use it any where else.(In this case i am using hot pink,because that would be the most ugly color for me :P ) so again form properties
BackColor=HotPink or Me.BackColor = Color.HotPinknow we have to set the TransparencyKey exaclty same to color we choose (in this case HotPink)
TransparencyKey=HotPink or Me.TransparencyKey = Color.HotPink
that's it! your form is now boderless and transparent and after some coding this will look like......
isn't it cool? now go make one for yourself :)
Does'n work for me.. Any Solution?
ReplyDeleteThank you very much!
ReplyDeleteThe code to move is fantastic and your designs are excellent.
It works for me..tnx u. It's a big help.
ReplyDeleteThank you very much!
ReplyDeleteBut I need a code that works on a picture for moving a form.
i didn't get it?could you be more specific plz.
Deletethanks
ReplyDeletewelcome :)
Deleteis this working on XP?
ReplyDeleteThe screen shot i mentioned in the post are in fact taken on windows xp.
Deleteworked on 2010 tnx
ReplyDelete