[2005] GDI and form borders
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
Re: [2005] GDI and form borders
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.
Re: [2005] GDI and form borders
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
Re: [2005] GDI and form borders
I am havin dificulty to imagen how do you want it to paint. If you could at least provide a screen shot of it could help.
1 Attachment(s)
Re: [2005] GDI and form borders
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? :blush:
Thank you again VBDT!! :wave:
D
Re: [2005] GDI and form borders
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?
Re: [2005] GDI and form borders
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).
:( :mad: :( :cry:
D
Re: [2005] GDI and form borders
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)
Re: [2005] GDI and form borders
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
1 Attachment(s)
Re: [2005] GDI and form borders
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.
Re: [2005] GDI and form borders
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
Code:
+----------------------+
| [TopPic] |
| +------------------+ | <--- form control
| | [BotPic] ||
| | (panel control) ||
| | ||
| +------------------+ |
+----------------------+
definitely consider a career in ascii art.
not sure how to do it, but sure, it can be done.
Re: [2005] GDI and form borders
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.....:ehh:
D