1

この質問を正確に表現する方法はよくわかりませんが、問題が何であるかを説明すると理解できます。

以下のWinFormのように、長方形、楕円形、線などの形状を描画するWinFormがあります。その後、それらの形状をバイナリファイルに保存します。

ここに画像の説明を入力してください

ただし、プログラムを起動して保存した図形を開くと、奇妙な理由で、winformにはペイントがたくさんあるにもかかわらず、図形が切り取られたように見える図形を表示するために、winformが設計時の幅と高さを維持していることに気付いた場合すべての形状を完全に描画する領域。

さらに、winformをリロードすると、現在の幅と高さを使用して形状が描画されます。したがって、winformは、以下のように私が期待しているようにも見えます。

ここに画像の説明を入力してください

私は何が欠けているか、何をする必要がありますか?したがって、winformは、実行時に常に現在の幅と高さに更新されます。

アップデート:

長方形を描画するためのコードは次のとおりです。Rectangleは、私のプログラム設計におけるクラスのオブジェクトです。したがって、各オブジェクトには独自の描画メソッドがあります。したがって、paintイベント内では、リスト内のすべてのオブジェクトが次のように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;
4

1 に答える 1

4
      g.FillPolygon(theBrush2,inpoints)

g変数は空から落ちました、それがどこから来たのかは不明です。しかし、結果から判断すると、おそらくCreateGraphics()を使用して、早期に初期化するという間違いを犯した可能性があります。これは正しく機能しません。Graphicsオブジェクトは、作成時のウィンドウのサイズを表すウィンドウのデバイスコンテキストから初期化されます。ウィンドウのサイズを変更しても、Graphics.ClipBoundsは変更できなくなります。

Paintイベントハンドラーで渡されたe.Graphicsオブジェクトを使用することが不可欠です。Draw()への引数として渡すだけです。クリップの境界が正しいことを確認するだけでなく、ダブルバッファリングを適切に機能させることも非常に重要です。

于 2012-06-05T13:06:26.633 に答える