6 Replies - 338 Views - Last Post: 15 June 2012 - 08:14 AM Rate Topic: -----

#1 theluvcat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-June 12

Problem, Transparency in VB.net

Posted 15 June 2012 - 05:20 AM

Hello all, I'm new to this forum and so first of all, want to say a big Hi.

I've recently begun programming in VB.net making the switch from VB 6.0. I'm having a problem with the transparency of images though; my problem is as follows.

I have 2 images that overlap, both images are PNG files (but I've also tried this with GIF aswell) and set the background of both image boxes to transparent. I then overalp the corners of the images boxes so that the top image box should show a portion of the bottom image; however, where they overlap I simply get the background colour obscuring the image that has the zorder of bottom.

I went back to VB6.0 and this and it works fine but seems that MS have not carried over this fundamental property of the image/picture box into VB.net (2005/2008 and 2010) - Does anyone know why

Could anyone please help me, I know there must be a way to allow the image box underneath the top image box to show.

Many, many thanks for your time and efforts reading and answering this post.
Warmest regards :bigsmile:

Is This A Good Question/Topic? 0
  • +

Replies To: Problem, Transparency in VB.net

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 957
  • View blog
  • Posts: 3,680
  • Joined: 02-July 08

Re: Problem, Transparency in VB.net

Posted 15 June 2012 - 06:19 AM

You can paint them both to a surface rather than host each in it's own control. In the paint event you use the e.DrawImage method.
Was This Post Helpful? 0
  • +
  • -

#3 theluvcat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-June 12

Re: Problem, Transparency in VB.net

Posted 15 June 2012 - 06:25 AM

Thanks for the reply _HAWK_, can you please give a little more information or point towards an example ??

Warmest regards
:rolleyes2:
Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,369
  • Joined: 16-March 11

Re: Problem, Transparency in VB.net

Posted 15 June 2012 - 06:44 AM

Good to see you around again Hawk.

@OP Open the form events drop down, and select the paint event. Then using the already provided E paint arguments, you can draw any image you wish.

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim k As Image = Image.FromFile("C:\Users\Trevor\Pictures\picrotated90.gif")
        e.Graphics.DrawImage(K, New Point(15, 15))
    End Sub



Drawing an image takes away the middle man(extra controls such as picture boxes). The picturebox control does the very same thing with the paint event, but you're painting on the picturebox surface rather than the form's surface.

All thanks to Hawk, he taught me the very same thing.

This post has been edited by trevster344: 15 June 2012 - 06:45 AM

Was This Post Helpful? 0
  • +
  • -

#5 theluvcat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-June 12

Re: Problem, Transparency in VB.net

Posted 15 June 2012 - 07:10 AM

Thanks @trevster344. Great idea however, I want to be able to turn the images on and off with logic statements. Will the painting if the images directly onto the form not inhibit this feature.

My original thought was to be able to say something like the following

(Pseudocode)

if (a == 1)
{
then imagebox1.visible = false
}

elseif (a == 0)
{
then imagebox1.visible = true
}

where a is a global variable (or maybe a class level variable) that is set elsewhere in the code.

Any thoughts would be greatly appreciated

Warmest regards
:bigsmile:
Was This Post Helpful? 0
  • +
  • -

#6 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,369
  • Joined: 16-March 11

Re: Problem, Transparency in VB.net

Posted 15 June 2012 - 07:20 AM

You can still do this.

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
if a = 1 then
       Dim k As Image = Image.FromFile("C:\Users\Trevor\Pictures\picrotated90.gif")
        e.Graphics.DrawImage(K, New Point(15, 15))
end if
    End Sub



Just fire the invalidate method of the form to refresh it.

me.invalidate



This way forces the form to redraw itself and initiate the paint event once more.

This post has been edited by trevster344: 15 June 2012 - 07:20 AM

Was This Post Helpful? 0
  • +
  • -

#7 theluvcat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-June 12

Re: Problem, Transparency in VB.net

Posted 15 June 2012 - 08:14 AM

Many thanks @trevster I'll give it a go and see how I get on.

Warmest regards
:smile2:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1