Results 1 to 5 of 5

Thread: [Resolved]send to back option in VB2005

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Resolved [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.

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: send to back option in VB2005

    Quote 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:
    1. Private Sub Form1_Paint(ByVal sender As Object, _
    2.                         ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    3.     e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, 175, 50)
    4. 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:
    1. Private Sub Form1_Paint(ByVal sender As Object, _
    2.                         ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint, _
    3.                                                                                 Panel1.Paint
    4.     Dim canvas As Control = DirectCast(sender, Control)
    5.     Dim position As New Point(175, 50)
    6.  
    7.     position = Me.PointToClient(canvas.PointToScreen(position))
    8.     e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, position.X, position.Y)
    9. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Re: send to back option in VB2005

    Quote 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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Re: send to back option in VB2005

    Quote 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:
    1. Private Sub Form1_Paint(ByVal sender As Object, _
    2.                         ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    3.     e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, 175, 50)
    4. 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:
    1. Private Sub Form1_Paint(ByVal sender As Object, _
    2.                         ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint, _
    3.                                                                                 Panel1.Paint
    4.     Dim canvas As Control = DirectCast(sender, Control)
    5.     Dim position As New Point(175, 50)
    6.  
    7.     position = Me.PointToClient(canvas.PointToScreen(position))
    8.     e.Graphics.DrawString("Hello World", Me.Font, Brushes.Black, position.X, position.Y)
    9. 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
  •  



Click Here to Expand Forum to Full Width