I'm using VS2008/.Net 3.5:
I didn't like the way the binding image was stretched to fill the graphic panel, so I made the following modifications:
In StartStep.cs , replace the original OnPaint() method with the code below:
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rect;
Rectangle iconRect;
RectangleF titleRect;
RectangleF subtitleRect;
base.OnPaint(e);
Graphics graphics = e.Graphics;
rect = LeftRectangle;
GetTextBounds(out titleRect, out subtitleRect);
Rectangle gradientRect = new Rectangle(rect.Location, rect.Size);
Rectangle bindingRect = new Rectangle(0, 0, 0, 0);
if (bindingImage != null)
{
bindingRect.Size = new Size(bindingImage.Size.Width, bindingImage.Size.Height);
if (bindingRect.Width != rect.Width)
{
float pct = (float)rect.Width / (float)bindingRect.Width;
bindingRect.Size = new Size(rect.Width, (int)(bindingRect.Height * pct));
}
gradientRect.Location = new Point(gradientRect.X, gradientRect.Y + bindingRect.Height - 1);
gradientRect.Size = new Size(gradientRect.Width, gradientRect.Height - bindingRect.Height);
}
using (Brush brush = new LinearGradientBrush(gradientRect, leftPair.BackColor1, leftPair.BackColor2, leftPair.Gradient))
{
graphics.FillRectangle(brush, gradientRect);
}
if (bindingImage != null)
{
graphics.DrawImage(bindingImage, bindingRect);
}
if (iconImage != null)
{
iconRect = IconRectangle;
iconRect.Inflate(-1, -1);
graphics.DrawImage(iconImage, iconRect);
}
DrawText(graphics, titleRect, title, titleAppearence);
DrawText(graphics, subtitleRect, subtitle, subtitleAppearence);
}
In IntermediateStep.cs , LicenseStep.cs , and FinalStep.cs , replace the original OnPaint() with this one:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics graphics = e.Graphics;
Rectangle rect = HeaderRectangle;
Rectangle rectangle;
RectangleF titleRect;
RectangleF subtitleRect;
Rectangle gradientRect = new Rectangle(rect.Location, rect.Size);
Rectangle bindingRect = new Rectangle(0, 0, 0, 0);
GetTextBounds(out titleRect, out subtitleRect);
if (bindingImage != null)
{
bindingRect.Size = new Size(bindingImage.Size.Width, bindingImage.Size.Height);
if (bindingRect.Height != rect.Height)
{
float pct = (float)rect.Height / (float)bindingRect.Height;
bindingRect.Size = new Size((int)((float)bindingRect.Width * pct), rect.Height);
bindingRect.Location = new Point(gradientRect.Width - bindingRect.Width, 0);
}
gradientRect.Location = new Point(gradientRect.X, gradientRect.Y);
gradientRect.Size = new Size(gradientRect.Width - bindingRect.Width, gradientRect.Height);
}
headerPair = new ColorPair(Color.White, Color.DarkSlateBlue, 180);
using (Brush brush = new LinearGradientBrush(gradientRect, headerPair.BackColor1, headerPair.BackColor2, headerPair.Gradient))
{
graphics.FillRectangle(brush, gradientRect);
}
if (bindingImage != null)
{
graphics.DrawImage(bindingImage, bindingRect);
}
titleAppearence.TextShadowColor = Color.Transparent;
titleAppearence.TextColor = Color.White;
subtitleAppearence.TextColor = Color.White;
subtitleAppearence.TextShadowColor = Color.Transparent;
DrawText(graphics, titleRect, title, titleAppearence);
DrawText(graphics, subtitleRect, subtitle, subtitleAppearence);
}
The code above resizes the bindingImage to fit inside the graphic panel, while maintaining the original aspect ratio of the image. It further changes the gradient rectangle so that it ends where the bindingImage starts, thus providing a reasonable transition from the gradient to the image. Of course, this only really looks good if the bindingImage has a single-color background, but you can also just set the gradient colors to be the same (essentially eliminating the gradient).
Other things I had to do:
0) I had to comment out all the pragma s because I kept getting compile errors.
1) I had to comment out the set functionality in the LeftPair property because I kept getting the serialization n compiler error.
2) I had to hard-code my gradient colors because the designer refused to keep the settings I made.
3) When I tried to set the bindingImage for the intermediate step page, I was getting an error from the IDE saying the setting already existed. All I did was click on it - I never got to the point where I could change the setting.
4) When I try to add a handler for normal form events, the method templates aren't being added to the application - anywhere.
IMHO, this could would be better if there were templates created to create the form and it's child pages. I think that would simplify the code and enable us to better isolate deficiencies.
I also think you would have been better served to create a StepBase class and put all the common stuff in it, such as the graphic panel, the binding image, and the gradient color pair stuff, just to name a few of the items.
Personal note to the author:
You seemed to have put a lot of work into the code, but you stopped far short of coming up with something viable. There is absolutely no reason for me to have to hard-code stuff into the control itself to make changes, especially with the effort you put into making the control compatible with the IDE designer. Further, you seem to have abandoned the code, forcing your users to try to figure out what the hell your code does. There is no documentation, and pitifully few comments, thus making the code a royal bitch to maintain. It now falls on someone else to take your c ode and recreate it in their own image, and hopefully post a new article with code that actually works.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|