Frage

I made this very simple application with .Net around 2 minutes, but I need to port it with Gtk# for properly working on Linux.

I searched how to make the background transparent but I have no luck; I searched also how to change the background color with the hope to find an equivalence of TransparenceKey, but no luck again.

The most important thing is this: How to do the background transparent?

Here's is the code of my app; it is written using Visual Studio 2010 and .Net Framework 4 Client Profile

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Calendario {
    public partial class Calendar : Form {
        private Timer temporizador;
        private Label lblHora, lblDia, lblFecha;
        public Calendar () {
            InitializeComponent ();

            this.BackColor = System.Drawing.Color.Lime;
            this.ClientSize = new System.Drawing.Size ( 1600, 900 );
            this.DoubleBuffered = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.TransparencyKey = System.Drawing.Color.Lime;

            temporizador = new Timer();
            temporizador.Tick += new System.EventHandler ( this.temporizador_Tick );
            temporizador.Interval = 1;
            temporizador.Enabled = true;

            lblHora = new Label();
            lblHora.AutoSize = true;
            lblHora.Font = new System.Drawing.Font ( "GE Inspira", 64F, System.Drawing.FontStyle.Regular,
                                                    System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
            lblHora.Location = new Point(1240, 12);
            lblHora.TextAlign = ContentAlignment.MiddleRight;
            lblHora.ForeColor = Color.FromArgb(255, 255, 32, 32);
            this.Controls.Add(lblHora);

            lblDia = new Label();
            lblDia.AutoSize = true;
            lblDia.Font = new System.Drawing.Font ( "GE Inspira", 36F, System.Drawing.FontStyle.Regular,
                                                    System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
            lblDia.Location = new Point(1430, 117);
            lblDia.TextAlign = ContentAlignment.MiddleRight;
            lblDia.ForeColor = Color.FromArgb(255, 255, 8, 8);
            this.Controls.Add(lblDia);

            lblFecha = new Label();
            lblFecha.AutoSize = true;
            lblFecha.Font = new System.Drawing.Font ( "GE Inspira", 28F, System.Drawing.FontStyle.Regular,
                                                    System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
            lblFecha.Location = new Point(1375, 186);
            lblFecha.TextAlign = ContentAlignment.MiddleRight;
            lblFecha.ForeColor = Color.FromArgb(255, 255, 0, 0);
            this.Controls.Add(lblFecha);
        }

        private void temporizador_Tick ( object sender, EventArgs e ) {
            lblHora.Text = DateTime.Now.ToString("HH:mm:ss");
            lblDia.Text = DiaDeLaSemana(DateTime.Now.DayOfWeek.ToString());
            lblFecha.Text = DateTime.Now.Date.ToShortDateString();
        }

        private string DiaDeLaSemana(string DayOfWeek) {
            switch (DayOfWeek) {
                case "Monday":
                    return "lunes";
                case "Tuesday":
                    return "martes";
                case "Wednesday":
                    return "miércoles";
                case "Thursday":
                    return "jueves";
                case "Friday":
                    return "viernes";
                case "Saturday":
                    return "sábado";
                default:
                    return "domingo";
            }
        }
    }
}

Thanks in advance for your help!

War es hilfreich?

Lösung

Compiz doesn't have window transparency on by default. http://www.jameswigley.com/2012/04/27/making-ubuntu-unity-look-beautiful-by-enabling-transparency/

To enable transparency on desktop Windows, follow these steps:

1) Install Compiz Config Settings Manager (if you haven’t already)
sudo apt-get install compizconfig-settings-manager compiz-plugins
2) Alt + F2, type ‘ccsm’ and press Enter to launch CCSM.
3) Click on the ‘Opacity Brightness & Saturation’ Plugin / ‘Opacity’ tab.
4) Click ‘New’. Click ‘+’ and a new window will appear. Click ‘Grab’ and then select the desktop window on which you want to enable transparency. The name will then be filled into the Value field. Click ‘add’. Range 0 (transparent) – 100 (opaque).
5) Transparency can the be changed via the Window Values slider .
Some common window classes are ‘Ccsm’,'Nautilus’,'Dialog’,'Normal’,'Empathy’,'Gedit’,'Gnome-Terminal’

Andere Tipps

I've searched more information about GTK and it doesn't have any 100% equivalence of TransparenceKey from .Net, I made some tests with semi-transparent backgrounds. But it isn't work the way I want. WinForms and GTK works in a VERY VERY DIFFERENT WAYS (I know that it's obvious), so I will close the question.

I'm sorry if I wasted your time...

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top