|
-
Aug 17th, 2007, 04:05 AM
#1
Thread Starter
Lively Member
[Resolved]send to back option in VB2005
Hi all;
Another night mare when learning the VB2005!
How can I send to back a picture in order to show other drawing in front of it? with VB six is just bu right click then select send to back and it is done, for VB2005 you can not either see the drawings at design time to select them and then select send to front option...
Am I making sense?
Last edited by M C Benzerari; Aug 20th, 2007 at 07:26 AM.
-
Aug 17th, 2007, 04:21 AM
#2
Re: send to back option in VB2005
It still is Right Click. When you right Click on a Control/Picture you will get two options of Bring to Front and Send to back.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Aug 17th, 2007, 04:39 AM
#3
Re: send to back option in VB2005
 Originally Posted by M C Benzerari
am I making sense?
Not completely. You talk about "pictures" but you don't mention whether you're talking about PictureBox controls, GDI+ drawings or something else. Be PRECISE when posting so we don't have to guess, because the answer will usually be different for different interpretations.
Here's what I'm guessing you're talking about. You're using GDI+ to draw on a form, i.e. using the Graphics object in the Paint event handler, and you want to know how get that drawing to be visible over the controls you've placed on the form. The answer is that you can't.
Programming objects work just like real-life objects. Imagine that you have a table and you draw on it. Now you put a mat on the table. How are you going to get the drawing to be visible on the mat? The answer is that you can't. You'd have to draw on the mat too. The answer is the same here: you'd have to draw on the control(s) too. That's quite easy to do though. You simply use one method to handle the Paint event for both the form and the control(s). You translate the coordinates to the form's world and then it looks like a single drawing. Try this:
1. Create a new Windows Forms Application project.
2. Add a Panel to the form.
3. Add this code:
vb.net Code:
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, 175, 50)
End Sub
4. Run the project and you'll see that the Panel obscures part of the drawn text.
5. Change the code to this:
vb.net Code:
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint, _
Panel1.Paint
Dim canvas As Control = DirectCast(sender, Control)
Dim position As New Point(175, 50)
position = Me.PointToClient(canvas.PointToScreen(position))
e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, position.X, position.Y)
End Sub
6. Run the project again and you'll see all the text, because it's drawn on the Panel too at the same location.
Just note that if that's not what you were talking about then I've wasted that time and effort and that's a perfect example of why you need to be clear in the first place.
-
Aug 17th, 2007, 07:43 AM
#4
Thread Starter
Lively Member
Re: send to back option in VB2005
 Originally Posted by Shuja Ali
It still is Right Click. When you right Click on a Control/Picture you will get two options of Bring to Front and Send to back.
Yes there is, but it has no effect as in VB6, the picture does not go back...I have tried it...
Thank you
-
Aug 17th, 2007, 07:47 AM
#5
Thread Starter
Lively Member
Re: send to back option in VB2005
 Originally Posted by jmcilhinney
Not completely. You talk about "pictures" but you don't mention whether you're talking about PictureBox controls, GDI+ drawings or something else. Be PRECISE when posting so we don't have to guess, because the answer will usually be different for different interpretations.
Here's what I'm guessing you're talking about. You're using GDI+ to draw on a form, i.e. using the Graphics object in the Paint event handler, and you want to know how get that drawing to be visible over the controls you've placed on the form. The answer is that you can't.
Programming objects work just like real-life objects. Imagine that you have a table and you draw on it. Now you put a mat on the table. How are you going to get the drawing to be visible on the mat? The answer is that you can't. You'd have to draw on the mat too. The answer is the same here: you'd have to draw on the control(s) too. That's quite easy to do though. You simply use one method to handle the Paint event for both the form and the control(s). You translate the coordinates to the form's world and then it looks like a single drawing. Try this:
1. Create a new Windows Forms Application project.
2. Add a Panel to the form.
3. Add this code:
vb.net Code:
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, 175, 50)
End Sub
4. Run the project and you'll see that the Panel obscures part of the drawn text.
5. Change the code to this:
vb.net Code:
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint, _
Panel1.Paint
Dim canvas As Control = DirectCast(sender, Control)
Dim position As New Point(175, 50)
position = Me.PointToClient(canvas.PointToScreen(position))
e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, position.X, position.Y)
End Sub
6. Run the project again and you'll see all the text, because it's drawn on the Panel too at the same location.
Just note that if that's not what you were talking about then I've wasted that time and effort and that's a perfect example of why you need to be clear in the first place.
I have tried your code it did not run OK, but you gave me a good logic, the last object drawn is shown in the front, and the first object drawn is left to the back.
Thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|