Link to home
Start Free TrialLog in
Avatar of schenkp
schenkp

asked on

Form Trick

HI,
I saw this cool trick with a program that I am trying to recreate.  If click and drag the form around the page it goes to 50% Opacity then when you let up it goes back to 100% opacity.  Anyone know how to make this happen?
Avatar of surajguptha
surajguptha
Flag of United States of America image

Did you see this on a Vista PC?
Avatar of schenkp
schenkp

ASKER

No,
Its one of the features with the nvidia 280NVS drivers, is it hard to duplicate?
It is very hard to replicate it on the Windows XP environment using GDI
However it is very easy to replicate it in Vista using WPF. using a feature called Aero

My opinion is that it will be hard to implement and nothing i know is available out of the box to change opacity to 50%
Avatar of Mike Tomlinson
@surajguptha...

What?!

.Net WinForms have an Opacity() property that does just that.  Set it at runtime to .5 for 50% opacity and 1 for normal "opaqueness" (no transparency at all).

If you have C# 2005 then use the ResizeBegin() and ResizeEnd() events.

Here is the code in VB.Net 2005:

    Public Class FormC
 
        Private Sub FormC_ResizeBegin(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeBegin
            Me.Opacity = 0.5
        End Sub

        Private Sub FormC_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
            Me.Opacity = 1
        End Sub

    End Class
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WoW !! It works !! :D
=)

If you have an earlier version of .Net then you would need to override the WndProc() method and trap the WM_ENTERSIZEMOVE / WM_EXITSIZEMOVE messages instead:
http://msdn2.microsoft.com/en-us/library/ms632622.aspx
http://msdn2.microsoft.com/en-us/library/ms632623.aspx


VB.Net:

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private Const WM_ENTERSIZEMOVE As Integer = &H231&
        Private Const WM_EXITSIZEMOVE As Integer = &H232

        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Select Case m.Msg
                Case WM_ENTERSIZEMOVE
                    Me.Opacity = 0.5

                Case WM_EXITSIZEMOVE
                    Me.Opacity = 1

            End Select

            MyBase.WndProc(m)
        End Sub

    End Class


C#:

    public partial class Form1 : Form
    {

        private const int WM_ENTERSIZEMOVE = 0x231;
        private const int WM_EXITSIZEMOVE = 0x232;

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_ENTERSIZEMOVE:
                    this.Opacity = .5;
                    break;

                case WM_EXITSIZEMOVE:
                    this.Opacity = 1;
                    break;                
            }

            base.WndProc(ref m);
        }

    }
cool stuff. I was just wondering if we can set opacity to just the top header of my form containing my form name and the minimise, maximise , close button area alone. I saw this feature in Vista being potrayed as something like a new technology. So was wondering if the same can be achieved in .net 2.0 itself on pre vista versions
That would be significantly more challenging as you would need to draw the nonclient area yourself...

I haven't worked with any of the new Vista (and consequently .Net 3.0) features myself.
Avatar of schenkp

ASKER

Nice