How do I make a form look like this
http://img415.imageshack.us/img415/5873/question6kz.jpg
?
The form is invisable but the things showing seem to be labels? Correct me if I'm wrong. How do I do this?
Printable View
How do I make a form look like this
http://img415.imageshack.us/img415/5873/question6kz.jpg
?
The form is invisable but the things showing seem to be labels? Correct me if I'm wrong. How do I do this?
what are you tryoing to do? i know how to make the form invisible and show only the controls on it.
I have to ask... would you WANT to make your form look like that? :confused:
In any case, the technique in use looks like regioning. Do a search on the forums for examples.
This will only make the controls show on the screen, with the rest of the form being invisible. Currently it only works with square items but can be easily modified for other shapes.
VB Code:
'To use this code, you'll need to put controls on the form. Make sure that one control can unload 'form or you won't be able to close it Const RGN_And = 1 Const RGN_COPY = 5 Const RGN_Or = 2 Const RGN_Xor = 3 Const RGN_DIFF = 4 Private Const CCHILDREN_TITLEBAR = 5 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type TITLEBARINFO cbSize As Long rcTitleBar As RECT rgstate(CCHILDREN_TITLEBAR) As Long End Type Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SetWindowRgn Lib "User32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Sub ReleaseCapture Lib "User32" () Const WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2 Private Declare Function GetTitleBarInfo Lib "user32.dll" (ByVal hwnd As Long, ByRef pti As TITLEBARINFO) As Long Private Sub Form_Load() Me.ScaleMode = vbPixels 'APIs work in pixels Dim tb As TITLEBARINFO Dim rgn1 As Long Dim rgn As Long Dim ctrl As Control tb.cbSize = Len(tb) GetTitleBarInfo Me.hwnd, tb tbh = tb.rcTitleBar.Bottom - tb.rcTitleBar.Top + 2.5 'The Bar Height rgn = CreateRectRgn(Me.Left, Me.Top + tbh, Me.Left + Me.Width, Me.Top + Me.Height + tbh) 'This is the form region For Each ctrl In Me rgn1 = CreateRectRgn(ctrl.Left + 2.5, ctrl.Top + tbh, ctrl.Left + ctrl.Width + 2.5, ctrl.Top + ctrl.Height + tbh) 'Every control's region is taken CombineRgn rgn, rgn, rgn1, RGN_Xor 'away from the main region Next SetWindowRgn Me.hwnd, rgn, True 'Set the form's shape to the region made DeleteObject rgn 'cleanup DeleteObject rgn1 End Sub
You can make the form invisible using the follwong code.
This goes in the general section
VB Code:
Public Const GWL_EXSTYLE = (-20) Public Const WS_EX_TRANSPARENT = &H20& Public Const SWP_FRAMECHANGED = &H20 Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1 Public Const SWP_SHOWME = SWP_FRAMECHANGED Or _ SWP_NOMOVE Or SWP_NOSIZE Public Const HWND_NOTOPMOST = -2 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
And this on the form
VB Code:
Private Sub Form1_Load( ) SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME End If
If you add a picture box, you should be able to see it.
It should work. If any problems, post here.
_________
If this post was helpful, please rate it
There is one issue with this approach. I've used this before, and encountered that fact that Labels will not show up when the form is made transparent. I've had no other problems with any other controls. I got "around" the problem by using a textbox as a label.Quote:
Originally Posted by khanjan_a2k
If you can keep frames opaque, could you not put the label in a frame?Quote:
Originally Posted by Hack
I don't believe I tried that. Give it a shot and see what happens.Quote:
Originally Posted by Dayjo
Well I couldn't seem to get that to work actually, it just seems to crash, no error just go all glitchy etc.
The fist example works fine though, with labels etc.