我用.Net做了這個非常簡單的應用程序大約2分鐘,但我需要使用Gtk#移植它,以便在Linux上正常工作。C#與GTK透明背景#
我搜索瞭如何使背景透明,但我沒有運氣;我也搜索瞭如何改變背景顏色,希望找到TransparenceKey的等價物,但沒有再次運氣。
最重要的是這個:如何做到背景透明?
這是我的應用程序的代碼;它是使用Visual Studio 2010和.Net Framework 4客戶端配置文件編寫的
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";
}
}
}
}
在此先感謝您的幫助!
如果我沒有解釋得很好,我很抱歉。我不想使用Compiz,我會知道是否可以使用GTK#設置透明背景,而不使用Composite Manager(Compiz,Xcompmgr等),或者如果可以使用alpha設置背景顏色。 如果沒有,我會尋找另一種可能性;但現在我知道這是否可能。 –
@CarlosMartínezMedina - 這是可能的http://stackoverflow.com/questions/3908565/how-to-make-gtk-window-background-transparent –