views:

645

answers:

1

Hi All,

I would like to know if it's possible to create nice form effects on the compact framework.

My plan is that when a user selects an image on the main form this is opened in a new form, this currently works. What I now want to do is make the form that contains the fullsize picture to load off the edge (left or right) of the screen at around 4 pixels high then slide into view. Once the form is fully on the screen then expand the height until it hits the max for the screen.

On close i would like to reduce the height back down to the 4 pixels high and the slide off the edge again before disposing the form.

I've tried the code below when instantiating the form and the dp.Top property was always 0 regardless of dp.Width == 240

DisplayPicture dp = new DisplayPicture(ImageUrl);
dp.WindowState = FormWindowState.Normal;
dp.Left = dp.Width * -1;
dp.Top = (dp.Height / 2) - 2;
dp.Height = 4;
dp.ShowDialog();

Within the DisplayPicture form i also have the following to try and move the form but as it isn't setting the Top property this code doesn't matter yet.

void t_Tick(object sender, EventArgs e)
{
    if (this.Left < 0)
        this.Left += 5;

    if (this.Left > -1)
    {
        this.Left = 0;
        if (this.Height < pictureBox1.ClientRectangle.Height)
        {
            this.Height += 4;
            this.Top -= 2;
        }

        if ((this.Left == 0) && (this.Top == 0))
            t.Enabled = false;

    }
}

Any help would be greatly appreciated!

TIA

OneSHOT

+1  A: 

To do this, start with a PictureBox control that has your image loaded. Set the Height to 4, the Width to the width of your form, and (very important) set the SizeMode of the PictureBox to StretchImage.

Next, position the PictureBox off the screen by setting Top to 0 and Left to -Width. Put a Timer control on your form with an interval of 100 (or whatever), and have its event gradually move the PictureBox to the right until its Left property is 0. Once you reach that point, have the timer event gradually increase the Height until it reaches the height of the form.

You'll probably have to deal with flicker, but this should get you started.

Update: I just read your question a little closer, and realized that you actually want to move the form itself from offscreen to full screen. This is not possible if you want the entire form (including the title bar at the top) to animate in this way, but you can sort of do this by setting the form's FormBorderStyle (or I think it's just called BorderStyle in the Compact Framework) to None. With the BorderStyle set to None, changing the Height, Width, Top and Left properties will actually have a visible effect on the form (although the form will be borderless). These properties are otherwise ignored completely in Windows Mobile, which is probably why your code didn't appear to be doing anything.

Update 2: here is my answer to a similar WM question, which may help you make your animated window look like a real window.

MusiGenesis
Spot on! Thanks it was the Border style that was stopping the code!
OneSHOT