Hi Giuliano C,
We received your project and I have taken a look.
The path you have chosen is to create a Custom Control, which is just fine, but you have to make some adjustments before you can expect the control to be rendered to your form.
First, regarding custom control, then from the attributes on your custom control, the MetaDataTag and Skin are the most relevant. The MetaDataTag is telling the rendering engine what type of control it should render, and as you are not supplying any XSLT, and you clearly want your control to be rendered as a normal PictureBox, then you should simply not set the MetaDataTag, and then it will inherit this setting from it's parent class, the PictureBox. The same rule applies to the Skin attribute. You're not changing any of the client resources, so you don't need it. Should you want to add some client resources (JavaScript etc...) you should make the Skin class inherit from PictureBoxSkin, and then add your additional client resources.
As I understand from your demo application, you are only customizing the server-side of the control, and in that case you really don't need it to be a custom control. Simply go right-click on your project, select Add / Inherited Control and select the Gizmox.WebGUI.Forms.PictureBox as the control to inherit from. This is a much simpler method, because then you don't have to worry about the extra stuff added by the Custom Control template. If you still want to go the Custom control way, then you should remove all the attributes from the class, and then remove the RenderAttributes method as well as the Text Property, after which you can delete the MyCustomControlSkin, as you will be using the default builtin PictureBoxSkin.
Anyway, using the Inherited control method, you can place this code in your control:
public partial class MyPictureBox : PictureBox
{
public MyPictureBox()
{
InitializeComponent();
if (this.ID == 0)
this.RegisterSelf();
this.Image = new GatewayResourceHandle(new GatewayReference(this, "test"));
this.SizeMode = PictureBoxSizeMode.Normal;
}
protected override IGatewayHandler ProcessGatewayRequest(Gizmox.WebGUI.Hosting.HostContext objHostContext, string strAction)
{
// Create a simple Image
Bitmap objBitmap = new Bitmap(10, 10);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 10, 10);
objHostContext.Response.ContentType = "image/jpeg";
objBitmap.Save(objHostContext.Response.OutputStream, ImageFormat.Jpeg);
return null;
}
Please note the two changes I made there. First, the "test" parameter to the GatewayReference constructor. Because how an Url is formed out of a GatewayRequest, it doesn't like an empty string, so place some dummy string there and you should be fine.
Second, the RegisterSelf() call deserves a special mention here. Every control (component) on a form in Visual WebGui will receive a unique ID when it's added to the form. This ID is used for the gateway request, as you can see if you view the rendered Html after you have shown the PictureBox. The way you construct your control, you are using the control's ID within the constructor. The constructor is invoked before the ID has been allocated, and as you are using the ID within the constructor (getting the GatewayReference to it), you must help with the process and make sure the ID is allocated before you use it. That's why you need to call RegisterSelf() in the constructor. This makes sure the ID is allocated, so you can use it in the next statement.
If you would skip this step of calling RegisterSelf(), your gateway request would always be issued against a component with the ID=0, which will most likely cause your gateway request to be "lost at sea", so to speak, and never reach your application, at least not your Picturebox.
Hope this explains,
Palli