Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to create an image with transparency placed on top of another image, inside a regular Gtk# window. The first image should be able to respond to mouse clicks.

The simple way would usually be to put an Image inside an EventBox - and inside the window. However, EventBox is not transparent by default, so even if the png Image itself has transparent areas, when inside the EventBox it shows as a square opaque background around the image.

I'm aware that EventBox can be made transparent using Cairo, but so far was not able to do that.

Can anyone provide a short C# example to make EventBox transparent?


share|improve this question
up vote 0 down vote accepted

Answering my own question...:

The solution is so simple, while I was looking for complex code to redraw the widget... All that needs to be done is to set the EventBox.VisibleWindow member to 'false' (it is 'true' by default). Than the EventBox is not drawn and if the image inside the EventBox has transparent areas, they will show what ever is below.

In the example below, it is:
mapBox.VisibleWindow = false;
pinBox.VisibleWindow = false;

As far as I could see, the Z-Order (which Widget is on top of which) is determined by the order of drawing on the screen (when the EventBox is not drawn, the EventBox.GdkWindow.Lower() or Raised() members are not doing anything).


// Showing a map in an invisible EventBox
EventBox mapBox = new EventBox();
mapBox.Visible = true;
mapBox.VisibleWindow = false;
fixed1.Move (mapBox, 0, 0);

Image mapImage = new Image("map.png");
mapImage.Visible = true;
mapBox.Add (mapImage);

// Showing a pin image with transparent areas, in an invisible EventBox, on top of the map
EventBox pinBox = new EventBox();
pinBox.Visible = true;
pinBox.VisibleWindow = false;
fixed1.Move (pinBox, 60, 60);

Image pinImage = new Image("redpin.png");
pinImage.Visible = true;
pinBox.Add (pinImage);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.