I am trying to learn how to draw over a form's border. As an interim I did the following:
Added Panel to form and made to size
Set the formboder=none and the backcolor = the transparency color on the form so that it is transparent and only the panel is visible
Set the Panels background image
Used Code to draw the border I want around the panel (basic as it is)
Now, I want to place an image in the center of the border around the panel, and have it half drawn on the form (which is in effect transparent) and half on the panel. It is just not working. I tried to use GDI to draw the image but it would not work right either. Here is what I have so far:
Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
Dim img As Image = Nothing
Try
img = Image.FromFile("C:\New Folder\GDITest\GDITest\912.gif")
Catch ex As Exception
End Try
If IsNothing(img) Then Exit Sub
Dim centerX As Integer = CInt((Me.Width / 2) - (img.Width / 2)) 'x coordinate
Dim centerY As Integer = Panel1.Top - (img.Height / 2) 'y coordinate
With PictureBox1
.Parent = Me
.BackgroundImage = img
.BackgroundImageLayout = ImageLayout.Stretch
.BorderStyle = BorderStyle.None
.Width = img.Width / 2
.Height = img.Height / 2
.Left = centerX
.Top = centerY
End With
'This is the GDI stuff that is not working,
'it places the image halfway on the panel only
'so that only half the image is visible.
'Dim cPoint As New Point(centerX, centerY)
'g.DrawImage(img, cPoint)
End Sub
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim g As Graphics = e.Graphics
Dim w As Integer = Panel1.Width
Dim h As Integer = Panel1.Height
'Pen Setup
Dim OuterBorderPen As New Pen(Color.Black, 2)
Dim InnerBorderPen As New Pen(Color.Gold, 1)
'Setup my rectangles
Dim outerRect As Rectangle = Me.ClientRectangle
Dim innerRect As New Rectangle(2, 2, w - 5, h - 5)
Dim innerRect2 As New Rectangle(4, 4, w - 8, h - 8)
g.DrawRectangle(OuterBorderPen, outerRect)
g.DrawRectangle(InnerBorderPen, innerRect)
g.DrawRectangle(OuterBorderPen, innerRect2)
'Tried to use this to make the image come to the forefront.
Panel1.SendToBack()
End Sub
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
Probably it is working but you don't see it because it is drawing on the form and under the panel so you don't see it. If you want to draw on the panel than use the panel paint event.
Rating is a way of saying thank you. Don't forget to rate always!
I tried to paint it onto the panels border, however it would only paint the bottom half. What I am trying to do is create an image on the border that comes partway into the panel and partway out. I switched to the form thinking it would make it easier to control and/or manipulate.
Thank you for your input though VBDT!!
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
Take a peek. You will notice that the transparent property of the picturebox overrides the panel, If I make the panel its parent then the opposite happens where the half that is in the invisible form does not show, in effect it cuts the picture in half. Fun learning new stuff huh?
Thank you again VBDT!!
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
So if I understand it right you want the bottom part of the image (the white part of the image be transparent so you could see the blue and green background. Is this right?
Rating is a way of saying thank you. Don't forget to rate always!
Yes so the top is "floating" and the bottom is on the panel/form. I am still researching and trying to figure this out and everything I try gives me the same result(s).
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
I don't think you will get any positive result of using panel.
I think it can be done in two ways.
1. You don't use panel and a picturbox but do all the drawings on the form.
2. you can cut the image and draw the up part on the panel and the buttom part on the picture box (this one is not a good one)
Rating is a way of saying thank you. Don't forget to rate always!
I guess I am more than a little confuzzled then. How do you draw shapes and pictures on the edge of forms? Drawing a line is easy, drawing an image is easy. getting the picture outside the bounds of the form or panel seems to be virtually impossible.
Thank you for your help, if anybody knows anything more or where I can look this up more please let me know!!
Thanks,
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
You don't and can't draw out side of the form. The only way to draw it outside of the form is that you draw it on desktop by getting the desktop DC and it is more complicated.
Why you want to draw outside of the form? Your form has no boarders and it is transparent: Here a little example check the attachment. These two images are drawn on the form and the form is transparent.
Rating is a way of saying thank you. Don't forget to rate always!
After reading through these posts and having no idea how to accomplish this, and playing with the form transparency and panels, I realized you should just put the whole thing inside the form, but only stretch the top part of the panel to some extent.. ill try to draw this out
My overall goal is to have a custom border on a control, namely a panel because I plan on putting textboxes, etc into it. I was originally thinking I could do it on a form, however I understand that I cannot move beyond the border of the form (without a whole lot of things I do not understand at this point). The problem I continue to have is that if I draw an image onto the form (using gdi) that I want to overlap the edge of the panel, the panel cuts off any part of the picture it covers. So how do I stop that from happening?? How do I make the parts of the image that extend onto the panel overlay what is in the panel (background, etc)??
Did I lose ya yet? Cause I need somebody to send out the coast guard for my sorry butt.....
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.