none
TransparencyKey in windows 7

    Question

  • It seems that the C# TransparencyKey doesn't work correctly in Windows 7. A form's TransparencyKey color is equal to its BackgroungColor and the controls' BackgroundColor are not the same. According to the mechanism, when the form is loaded, we can only see and operate the controls, the other part of this form is not available. However this works well in Windows XP but incorrectly in Windows 7. In Windows 7,we can still operate the other part. What's the matter?


    In another word, in Windows 7, the mouse can't penetrate the completely transparent form while in Windows XP, the mouse can do that.
    • Moved by edhickey Thursday, April 28, 2011 5:44 PM (From:.NET 4: Windows Workflow Foundation)
    • Moved by Leo Liu - MSFT Friday, April 29, 2011 5:37 AM Moved for better support. (From:Visual C# General)
    • Edited by YeHong Tuesday, June 21, 2011 12:45 PM
    Thursday, April 28, 2011 3:49 AM

Answers

  • Try to use the Gray color as the TransparencyKey, I test many color and this can solve your issue.

          this.BackColor = Color.Gray;
          this.button1.BackColor = Color.Blue;
          this.TransparencyKey = Color.Gray;
    

     

    And seems one should be Red = Green = Blue (gray color), so I test other likes: #222222 #888888 # AAAAAA etc. all can work.

          this.BackColor = Color.FromArgb(0xAA,0xAA,0xAA);
          this.button1.BackColor = Color.Blue;
          this.TransparencyKey = Color.FromArgb(0xAA, 0xAA, 0xAA);
    

     

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by YeHong Monday, May 02, 2011 11:25 AM
    Monday, May 02, 2011 2:34 AM
    Moderator

All replies

  • Hi YeHong,

    Could you please show some specific code that you use the TransparencyKey in C# in (Winform or WPF?)? Windows 7 introduces the Aero theme, and some behaviour may be different with XP, we should discuss it on the specific scenario. Thnaks.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 29, 2011 7:08 AM
    Moderator
  • Hi Bob Bao,

    Thank you for your reply. Yes, it's cased by the Aero theme. If I do not use the Aero theme, the application works as well as in Windows XP.

     I built my application in Winform, the specific codes are following:

            public Form1()
            {
                InitializeComponent();

                this.StartPosition = FormStartPosition.Manual;
                this.Location = new Point(300, 300);
                this.Size = new Size(300, 300);

                this.FormBorderStyle = FormBorderStyle.None;

                this.BackColor = Color.Red;
                this.button1.BackColor = Color.Blue;
                this.TransparencyKey = Color.Red;
            }

    If it works well, we can only see the button1, and the other part of Form1 will be completely transparent and invisable ,also can not receive mouse event. In the Windows XP, it runs as expected, only the button1 is visable and can hold the mouse event. However, when I turn to Window 7,though only the button1 is visable, the whole Form1 holds the mouse event. Which is to say the screen rectangle region (300,300,600,600) holds the mouse event not only button1.

    How can I solve this problem?


    • Edited by YeHong Monday, May 02, 2011 11:27 AM
    Friday, April 29, 2011 10:38 AM
  • Try to use the Gray color as the TransparencyKey, I test many color and this can solve your issue.

          this.BackColor = Color.Gray;
          this.button1.BackColor = Color.Blue;
          this.TransparencyKey = Color.Gray;
    

     

    And seems one should be Red = Green = Blue (gray color), so I test other likes: #222222 #888888 # AAAAAA etc. all can work.

          this.BackColor = Color.FromArgb(0xAA,0xAA,0xAA);
          this.button1.BackColor = Color.Blue;
          this.TransparencyKey = Color.FromArgb(0xAA, 0xAA, 0xAA);
    

     

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by YeHong Monday, May 02, 2011 11:25 AM
    Monday, May 02, 2011 2:34 AM
    Moderator
  • Hi Bob Bao,

    Thank you very much, the gray color works quite well.


    Monday, May 02, 2011 11:26 AM
  • Sorry to jump on an old thread - but I am having the same but also the opposite problem!

    I developed a simple app on a Win 7 machine with an odd color (not GRAY) - and it appeared transparent BUT IT DID CATCH the mouse enter event.

    And I wanted it to do this - so I was happy.  On MOUSE ENTER I was enabling the form - so basically hovering into a corner of my screen brought up this invisible form.

    Then I went to test it on XP and it would NOT CATCH the MOUSE ENTER event.

    Which after I read this thread - I understand - if I change the color to GRAY it won't work on WIN 7 either.

    My goal is to make an invisible region on the screen that when you mouse into will BRING UP a form that was previously hidden (transparent).

    Thanks in advance!

    Wednesday, October 05, 2011 8:13 PM