Showing posts with label usercontrol. Show all posts
Showing posts with label usercontrol. Show all posts

Friday, July 31, 2009

Creating an Image from a User Control - C#

I wanted to create an image from a "screen shot" of my user control. I wanted to be able to save a picture of the user control at any given moment, save that image to a file for later use.

It's easy!

1. Create a Bitmap object of the size of your control.
Bitmap picture = new Bitmap (800, 600);

2. Create a Graphics object from the Bitmap Object.
Graphics graphx = Graphics.FromImage(picture);

3. Draw your user control to the Graphics object.
CreateControl(graphx);

4. Save your picture to a file.
picture.Save(@"C:\ControlImage.bmp");

It's that simple!

Thursday, April 23, 2009

ASP.NET MVC usercontrol

There are a few things I found out about ASP.Net MVC user controls.

1. The user control cannot be contained in asp:content blocks.  The code must be in "the open".
2. You can pass the ViewData as a parameter.
3. To render the user control you must:



4. You do not need the '.ascx' after the name of the view.