[Mono-winforms-list] Transparent Window not transparent under ubuntu

grayarea56 at gmail.com grayarea56 at gmail.com
Tue Mar 29 16:02:21 UTC 2016


Hi all,
I'm trying to port my windows c# software to run on linux using mono.

First of all, I'm a linux and mono newbie!  really simple things take me a
long time! :-(

However, after a fair amount of work, mostly, things are working, 
but I have one serious problem:

My star chart has a transparent window in front of it, where I draw the
position 
of the telescope, satellites, etc.

It's been working on windows (version XP  up to version 10) for years,
but on ubunto, it is white (not transparent), so you can't see the stars,
constellations, galaxies, etc.

So, I'm using this in my transparent form class constructor:

            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            UpdateStyles();
            this.BackColor = Color.Empty;
            this.TransparencyKey = BackColor;

This works on windows, but doesn't on ubuntu, release 14.10.
I'm using:
Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:20:38
UTC 2016)

Also, I'm using virtualBox mananager to create my ubuntu, I'm not sure if
that would have an effect.

Do you think this is an ubuntu issue?
VirtualBox issue?
My implementation?
Mono issue?

I've read on the forum that "IF" the underlying operating system supports
transparent form, 
then mono will.
But I'm not sure if I'm doing something wrong, 

Here's a "windows" screenshot of what it's supposed to look like.
Notice the little "bug" thingy to the upper right of the yellow sun, 
That is the position of the telescope, and is being drawn 
on the transparent window.
http://siderealtechnology.com/SkyViewSceenShot.jpg


Thanks a million, 

Dan Gray
http://siderealtechnology.com


Here's the complete code for the class:
    //***************************************************
    internal class TranspForm : Form
    { 
        Form MomF = null;
        internal Font ThisFont;
        internal TranspForm(Form f)
        {//constructor, do nothing!
            if (f != null)
            {
                this.Owner = f;
                MomF = f;
            }
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            UpdateStyles();
            this.BackColor = Color.Empty;
            this.TransparencyKey = BackColor;
            SetTransparentWindowSize();
            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            ShowInTaskbar = false;
            Show();
            BringToFront();
            ThisFont = new Font("Times New Roman", 10);
        }

        internal void SetTransparentWindowSize()
        {
            if (MomF != null)
            {
                this.Location = MomF.PointToScreen(new Point(0, 0));
                this.Height = MomF.ClientRectangle.Size.Height;
                this.Width = MomF.ClientRectangle.Size.Width;
            }
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
        }
        internal void InvalidateEx()
        {
            this.Invalidate();
        }
        protected override void WndProc(ref Message m)
        {//this makes mouse clicks, etc, go through to form underneath
(thank g for the internet!)
            if (m.Msg == 0x0084) m.Result = (IntPtr)(-1);
            else base.WndProc(ref m);
        }
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle = cp.ExStyle | 0x20;
                return cp;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.Clear(this.BackColor);
            base.OnPaint(e);
            e.Graphics.Dispose();
        }
    }





--
View this message in context: http://mono.1490590.n4.nabble.com/Transparent-Window-not-transparent-under-ubuntu-tp4667627.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.


More information about the Mono-winforms-list mailing list