GTK# Widget in front of another widget

2019-08-12 05:22发布

问题:

How to bring a widget to the front of another widget? I want to put the timeLeft Label in front of the box DrawingArea

My Code :

box.SetSizeRequest((int)Math.Floor(size*2.5), size);
box.ExposeEvent += boxExpose;
theMainWindow.winFix.Put(box, x, y);
box.Show();

Pango.FontDescription fontdesc = Pango.FontDescription.FromString("Lucida Console " + (size - 6));
timeLeft.ModifyFont(fontdesc);
timeLeft.SetSizeRequest((int)Math.Floor(size*2.5)-6, size-6);

theMainWindow.winFix.Put(timeLeft, x+3, y+3);   
timeLeft.Show();

回答1:

So Labels in gtk# don't have there own gdk window and draw on to the parent widget (the window in this case). To get around this you can wrap the label in an EventBox widget and add that to the window. This works because the event box is giving the label a window to draw on.