Click here to Skip to main content
16,017,151 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)
See more:
I need to make a screen which acts as a lockscreen.
what i am trying to make is similar to the following:
'in the utility mosaic which tries to imitate the windows8 start screen, the clock widget when clicked causes a screen to drop down from the top of the screen. this screen is a full screen wallpaper type thing that also shows the time. what is interesting is that it doesn't allow clicks to pass through it to the desktop or to the mosaic app itself. to reach the desktop or the mosaic app, you have to grab this screen at its bottom using the mouse-leftclick-hold and drag the screen upwards to about 3/4 of the screen after which this screen automaticaly retracts. this is somewhat similar to the *slide to unlock* thing on many touchscreen mobiles.'

now, a windows form can be made and dynamically sized to cover the entire screen. It can be set as topmost so that mouse-clicks do not go through it. then one needs to disable alt+tab and 'win' keys to prevent user from directly accessing desktop or taskbar. also disabling form border will disable its minimize, maximize and close buttons.

what i am concerned about is how to make it appear to slide downwards the bottom when the lock is engaged and how to get it to respond to a mouse-click-drag towards the top till some 3/4th of the screen to cause it to retract??? how can i do these animation kind of effect???

plus, i need to have just a single button on this form which can enable the drag-to-retract property so that either a user can engage this slide-to-lock screen and then further lock it in place so that it wont retract or move by dragging until the button is clicked after which the user can slide-it off... like a 2 stage lock.
Posted
Comments
Manfred Rudolf Bihy 15-Jul-11 4:19am    
Ahhh, the scent of specific requirements in the morning ...
Have my 5 for laying out your requirements so nicely.
Philippe Mori 15-Jul-11 21:06pm    
Why not make it a screen saver?
princektd 16-Jul-11 8:48am    
its kind of a screensaver u can say... but i need it specifically to act as a locking screen for a touchscreen app...
princektd 16-Jul-11 8:48am    
thnx Manfred R. Bihy

A slide effect can be achieved by changing the size (and position, in some cases, but sliding to/from the top of the screen doesn't require that) on a timer. All animation of standard controls requires use of a timer.

To respond to a drag, the typical approach is to set a flag on mouse down, unset it on mouse up, and in a mouse move handler perform your drag logic.
 
Share this answer
 
Comments
princektd 16-Jul-11 8:49am    
i figured i would need a timer. but how do i move the form???
The animation isn't too difficult: all you have to do is cheat.
1) Take a screen grab.
private Bitmap GetScreen()
    {
    Rectangle screenRegiion = Screen.AllScreens[0].Bounds;
    Bitmap grab = new Bitmap(SystemInformation.PrimaryMonitorSize.Width,
                             SystemInformation.PrimaryMonitorSize.Height,
                             PixelFormat.Format32bppArgb);
    using (Graphics screenGraphics = Graphics.FromImage(grab))
        {
        screenGraphics.CopyFromScreen(screenRegiion.Left, screenRegiion.Top, 0, 0, screenRegiion.Size);
        }
    return grab;
    }

2) Make your form cover the entire display, and show the screen grab. This uses a picture box, but you could handle the paint event
private void showPic(Image pic)
    {
    // Get the size of the image
    int xsize = pic.Width;
    int ysize = pic.Height;
    int x = SystemInformation.PrimaryMonitorSize.Width;
    int y = SystemInformation.PrimaryMonitorSize.Height;
    ClientSize = new System.Drawing.Size(x, y);
    FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    BackColor = System.Drawing.Color.Black;
    Location = new System.Drawing.Point(0, 0);
    int yout = SystemInformation.PrimaryMonitorSize.Height;
    int xout = (int) SystemInformation.PrimaryMonitorSize.Height * xsize / ysize;
    if (xout > SystemInformation.PrimaryMonitorSize.Width)
        {
        //Retain aspect ratio
        yout = (int) SystemInformation.PrimaryMonitorSize.Width * ysize / xsize;
        xout = SystemInformation.PrimaryMonitorSize.Width;
        }
    pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    pictureBox1.Location = new System.Drawing.Point((SystemInformation.PrimaryMonitorSize.Width - xout) / 2, (SystemInformation.PrimaryMonitorSize.Height - yout) / 2);
    pictureBox1.Size = new System.Drawing.Size(xout, yout);
    pictureBox1.Image = pic;
    }
Don't forget to hide any controls you already have!
4) Using a timer, slowly "slide" your picture down over the screen grab. This is pretty simple: Graphics.DrawImage with an increasing Y offset, and an invalidate.
5) Handle some event so that you can cancel the lock and re-display the normal screen!
 
Share this answer
 
Comments
princektd 16-Jul-11 8:44am    
i need to slide the whole form... say Form1 is the 'home screen' hosting the buttons. one of these buttons is for locking. clicking on this lock button has to create a new instance of a form, say Form2, and have Form2 slide down from the top to the bottom. also, Form2 has to be fullscreen, so size change is not an option... this doesnt mean i have to hide or disable Form1. Form1 must still be active but under Form2 untill Form2 is dragged upwards again to 'unlock'...
To slide down, you need to change Location and/or Size of your wallpaper-showing window. Start near the top, then gradually set your window to move lower and lower.

That for you will need some events to trigger the Location change. Typically you would use a System.Windows.Forms.Timer set to Interval = 40ms.

I personally would also run a System.Diagnostics.Stopwatch to control the window motion. Timer to create the event, Stopwatch to process exact location. This is because Stopwatch.ElapsedMilliseconds's precision is a lot better than that of a Forms.Timer.

So you would have something like
double panningTimeMs = 500D;
private void PanningTimer_Tick( object sender, EventArgs e)
{
    int elapsedMilliseconds = _panningStopwatch.ElapsedMilliseconds;
    if( elapsedMilliseconds > panningTimeMs)
    {
        _panningTimer.Stop();
        elapsedMilliseconds = panningTimeMs;
    }

    int windowTop = -this.Height + ( this.Height * elapsedMilliseconds / panningTimeMs);

    this.Location = new System.Drawing.Point( this.Location.X, windowTop);
}


For detecting the upwards slide, override OnMouseDown. Check mouse position and decide whether it qualifies as movement starting point. Set a member field if it does.

Override OnMouseMove and check whether you're in sliding mode (that's what the member field was for). If so, check mouse position. If it is far enough up the screen, remove the lock.

Finally, override OnMouseUp as well and check for sliding mode. Reset the mentioned member field if mouse position is still to near the bottom to release lock.

For the extra double-lock button, you could use a System.Windows.Forms.CheckBox with Appearance = Appearance.Button. If checked, the button will remain pressed, until you uncheck it. You could then check the Checked property to determine if you do all the other sliding stuff.
 
Share this answer
 
v2
Comments
princektd 16-Jul-11 8:59am    
Thnx.

**To slide down, you need to change Location**
But how do I do that???

More clearly, say Form1 is the 'home screen' hosting the buttons. one of these buttons is for locking. clicking on this lock button has to create a new instance of a form, say Form2, and have Form2 slide down from the top to the bottom. Form1 should not be hidden of closed or disabled. Form1 must still be active but under Form2 untill Form2 is dragged upwards again to 'unlock'.

Now, when Form2 is created, it initially must be offscreen, with its bottom edge lying on the screen's top edge... similar to how your windows taskbar autohide looks when the taskbar is positioned at top and hidden.... the taskbar's bottom edge is just visible on the top edge of the screen. when mouse touches it, the taskbar slides down to reveal itself...

similarly, when the lock form Form2 is created, only its bottom edge must be visible and it must slide down till it covers the screen. it is to be dynamically sized coz it has to be fullscreen and users may have various screen resolutions... so i dont know if resizing is a good option to achieve this effect...

so how do i change the form's location to cause it to move downwards till Form2's bottom edge hits the screens bottom edge (ie, how to move it till the screen is fully in place)? how do i calculate this movement with respect to Form2's bottom edge?

If you could, please say which function i could use for changing location...

thnx
lukeer 18-Jul-11 2:34am    
>> **To slide down, you need to change Location**
>But how do I do that???

Set the locking form's Location property to a new value. That's all.
this.Location = new System.Drawing.Point( 100, 20);
will set the upper left corner of the window it affects to 100 pixels from the left and 20 pixels from the top. Use negative values to achieve positions over or left of the border.
princektd 16-Jul-11 9:01am    
and i plan to use a simple timer tick as a trigger for the location code... one button click on the main form triggers the lockscreen form which then moves down based on timer tick and covers the whole screen in about 5 seconds...
princektd 18-Jul-11 6:28am    
ok...
so, Location affects from the uppr left corner of the form.
So if the form is 1024*768 size, then

this.Location = new System.Drawing.Point( -1023, -767);

would do the job, I think???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900