I have a C# Winform where Im drawing some rectangles.
I have set all the variables (width, height, x, y) of all rectangles so it can fit in the actual size of the picture box.
What I want is to resize my form and also resize all my drawings. Would be great if by default the drawing fits the entire picturebox area.
This is the window form.
If I resize this is the actual result:
This is my code:
private void pbBox_Paint(object sender, PaintEventArgs e)
{
Rectangle leftInsertionBox = new Rectangle(_leftPadding, _topPadding + _boxBase, _insertion, _boxFront);
Rectangle leftCoverBox = new Rectangle(_leftPadding + leftInsertionBox.Width, _topPadding + _boxBase, _boxBase, _boxFront);
Rectangle leftTopDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width - (_insertion + _boxBase) / 2, _topPadding, (_insertion + _boxBase) / 2, _boxBase);
Rectangle rightTopDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight, _topPadding, (_insertion + _boxBase) / 2, _boxBase);
Rectangle topRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding, _boxHeight, _boxBase);
Rectangle frontRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + _boxBase, _boxHeight, _boxFront);
Rectangle leftBottomDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width - (_insertion + _boxBase) / 2, _topPadding + topRect.Height + frontRect.Height, (_insertion + _boxBase) / 2, _boxBase);
Rectangle rightBottomDustBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight, _topPadding + topRect.Height + frontRect.Height, (_insertion + _boxBase) / 2, _boxBase);
Rectangle bottomRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + _boxBase + _boxFront, _boxHeight, _boxBase);
Rectangle backRect = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + _boxBase + _boxFront + _boxBase, _boxHeight, _boxFront);
Rectangle rightCoverBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight, _topPadding + _boxBase + _boxFront + _boxBase, _boxBase, _boxFront);
Rectangle rightInsertionBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width + _boxHeight + rightCoverBox.Width, _topPadding + topRect.Height + frontRect.Height + bottomRect.Height , _insertion, _boxFront);
Rectangle bottomGlueBox = new Rectangle(_leftPadding + leftInsertionBox.Width + leftCoverBox.Width, _topPadding + topRect.Height + frontRect.Height + bottomRect.Height + backRect.Height, _boxHeight, _glue);
// solid brush
SolidBrush myBrush = new SolidBrush(System.Drawing.Color.LightGray);
LinearGradientBrush linearGradientBrush = new LinearGradientBrush(topRect, Color.Red, Color.Yellow, 90);
ColorBlend cblend = new ColorBlend(3);
cblend.Colors = new Color[3] { Color.Red, Color.Yellow, Color.Green };
cblend.Positions = new float[3] { 0f, 0.5f, 1f };
linearGradientBrush.InterpolationColors = cblend;
using (Pen pen = new Pen(Color.DarkGray, 1))
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
DoRotation(e);
e.Graphics.DrawRectangle(pen, leftInsertionBox);
e.Graphics.DrawRectangle(pen, leftCoverBox);
e.Graphics.DrawRectangle(pen, leftTopDustBox);
e.Graphics.DrawRectangle(pen, rightTopDustBox);
e.Graphics.DrawRectangle(pen, leftBottomDustBox);
e.Graphics.DrawRectangle(pen, rightBottomDustBox);
e.Graphics.DrawRectangle(pen, topRect);
e.Graphics.FillRectangle(myBrush, topRect.X+1,topRect.Y+1,topRect.Width-1,topRect.Height-1);
e.Graphics.DrawRectangle(pen, frontRect);
e.Graphics.FillRectangle(myBrush, frontRect.X + 1, frontRect.Y + 1, frontRect.Width - 1, frontRect.Height - 1);
e.Graphics.DrawRectangle(pen, bottomRect);
e.Graphics.FillRectangle(myBrush, bottomRect.X + 1, bottomRect.Y + 1, bottomRect.Width - 1, bottomRect.Height - 1);
e.Graphics.DrawRectangle(pen, backRect);
e.Graphics.FillRectangle(myBrush, backRect.X + 1, backRect.Y + 1, backRect.Width - 1, backRect.Height - 1);
e.Graphics.DrawRectangle(pen, rightCoverBox);
e.Graphics.DrawRectangle(pen, rightInsertionBox);
e.Graphics.DrawRectangle(pen, bottomGlueBox);
}
}
Any clue?