C# magic forms, From Code4Fun session in TechDays 2009

Hi everyone, and welcome to the first post in my new technical blog.

After being in the Coding 4 Fun session in Microsoft TechDays 2009 in Paris http://www.microsoft.com/france/mstechdays/, I was inspired by a simple application made in that session, which is just some windows on the desktop, and when you move those windows you have the impression that they show an image in the background, as shown in the following picture:

The principle of that simple application is that whenever you double-click a window you get a new view of the image in the background.

The trick is so simple in fact, the first step is to create a pictureBox and adjust their position and dimensions accordingly.
We just capture the move event and change the dimenstions as follows:

 private void form1_move(object sender, EventArgs e)
            pictureBox1.Left = -this.Left;
            pictureBox1.Top = -this.Top;
            form1_resize(this, null);

        private void form1_resize(object sender, EventArgs e)
            pictureBox1.Width = this.Left + this.Width;
            pictureBox1.Height  = this.Top + this.Height;

And to make things more cooler, we just create new views (windows) of the background image from the principle Form when we double-click a Form like that:

        private void doubleclick(object sender, EventArgs e)
            var f = new Form1();

PS: A simple application of such an app, is tu use a windows to hide icons from the desktop for example.

Posted in . Bookmark the permalink. RSS feed for this post.

comments powered by Disqus

Swedish Greys - a WordPress theme from Nordic Themepark. Converted by LiteThemes.com.