我不太确定如何准确地表达这个问题,但是在我解释了问题所在之后你就会明白了。
我有一个 winform,我可以在上面绘制矩形、椭圆形、线条等形状,就像下面的 winform 一样。之后,我将这些形状保存到二进制文件中。
但是,如果您注意到当我的程序启动并打开保存的形状时,出于某种奇怪的原因,winform 会保持其设计时宽度和高度以显示形状看起来被切掉的形状,即使 winform 有大量的油漆区域以完全绘制所有形状。
此外,如果我重新加载 winform,它会使用当前的宽度和高度来绘制形状。因此,winform 看起来也像我所期望的那样,如下所示。
我错过了什么或需要做什么?因此,winform 将在运行时始终更新为其当前的宽度和高度。
更新:
这是绘制矩形的代码。矩形是我的程序设计中的一个类的对象。因此,每个对象都有自己的绘制方法。因此,在绘制事件中,列表中的所有对象都调用 draw 方法,如下所示。
method ViewFrmpas.ViewFrmpas_Paint(sender: System.Object; e: System.Windows.Forms.PaintEventArgs);
begin
myObjects.Draw;
end;
这是我在winform上绘制矩形的实际绘制方法。
method TMakerRect.Draw;
var
outpoints:Array of point;
inpoints:Array of point;
r,fr:Rectangle;
midx,midy:integer;
theBrush1:HatchBrush;
theBrush2:SolidBrush;
begin
r := bounds;
fr := bounds;
if (theBrushStyle = HatchStyle.Wave) then
theBrush1 := new HatchBrush(theBrushStyle,Color.Transparent,color.Transparent)
else if (theBrushStyle = HatchStyle.ZigZag) then
thebrush2 := new SolidBrush(FillColor)
else
theBrush1 := new HatchBrush(theBrushStyle,FillColor,color.Transparent);
if (thePen.DashStyle = DashStyle.Custom) then
thepen.Color := Color.Transparent;
outpoints := new point[5];
inpoints := new point[4];
with r do
begin
midx := ((right - left) div 2) + left;
midy := ((bottom - top) div 2) + top;
inpoints[0].x := left; inpoints[0].y := top;
inpoints[1].x := right; inpoints[1].y := top;
inpoints[2].x := right; inpoints[2].y := bottom;
inpoints[3].x := left; inpoints[3].y := bottom;
end;
if Active then
begin
Fill(var fr);
with fr do
begin
outpoints[0].x := r.Left; outpoints[0].y := r.Top;
outpoints[1].x := left; outpoints[1].y := top;
outpoints[2].x := right; outpoints[2].y := top;
outpoints[3].x := right; outpoints[3].y := bottom;
outpoints[4].x := left; outpoints[4].y := bottom;
end;
Scale(var inpoints,4,midx,midy);
Rotate( var inpoints,4,midx,midy);
Translate(var inpoints,4);
Scale(var outpoints,5,midx,midy);
Rotate( var outpoints,5,midx,midy);
Translate(var outpoints,5);
if Visible then
begin
if theBrushStyle = HatchStyle.ZigZag then
g.FillPolygon(theBrush2,inpoints)
else
g.FillPolygon(thebrush1,inpoints);
g.DrawPolygon(thepen,outpoints);
end;
end
else
begin
outpoints[0].x := r.Left; outpoints[0].y := r.Top;
outpoints[1].x := r.left; outpoints[1].y := r.top;
outpoints[2].x := r.right; outpoints[2].y := r.top;
outpoints[3].x := r.right; outpoints[3].y := r.bottom;
outpoints[4].x := r.left; outpoints[4].y := r.bottom;
if theBrushStyle = HatchStyle.ZigZag then
g.FillPolygon(thebrush2,inpoints)
else
g.FillPolygon(theBrush1,inpoints);
g.DrawPolygon(thepen,outpoints);
end;
end;