小弟刚进公司不久,想好好表现,但是遇到一个问题,请大侠帮帮小第:如下把一个正圆分割成四块(用垂直线+水平线分割),然后根据combobox里不同的四个不同内容,分别把这个被分成四块的正圆涂黑,如选择1则涂黑右上,2则涂黑右半……4则全涂黑我有一个想法就是放一个圆形panel,然后分别在panel的四个角放四个edit,需要涂黑时就把edit背景改成黑色,但现在不知道如何搞定圆形panel另外这个凑出来的‘图形’如何打印?不知道我说清了没,或者那位大侠有更好的办法请指点,小弟定感激不进!

解决方案 »

  1.   

    即是顯示一個圖像就應該用: TShape  ,設置 Shape 的 shape   為stCircle,再開始畫吧。
      

  2.   

    还有我这个圆是放在ScrollBox里的(因为form的高度不够),这样的话也能确定坐标吗?
      

  3.   

    procedure TForm1.img1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);  //当 鼠标 单击Image控件时
    var
      x1,y1:Integer;//绘画区域 左上角 坐标
      x2,y2:Integer;//绘画区域 右下角 坐标
      x3,y3:Integer;//圆水平分割线 左端点 坐标
      x4,y4:Integer;//圆水平分割线 右端点 坐标
      x5,y5:Integer;//圆垂直分割线 上端点 坐标
      x6,y6:Integer;//圆垂直分割线 下端点 坐标
      x7,y7:Integer;//圆水平、垂直分割线 交点 坐标
    begin
      //清除 Canvas上原有内容
      img1.Canvas.Brush.Color:=clWhite;
      img1.Canvas.FillRect(img1.ClientRect);
      //获得 关键点坐标
      x1:=0;
      y1:=0;
      x2:=img1.Width;
      y2:=img1.Height;  x3:=x1;
      y3:=(y2-y1) div 2;
      x4:=x2;
      y4:=y3;  x5:=(x2-x1) div 2;
      y5:=y1;
      x6:=x5;
      y6:=y2;  x7:=(x4-x3) div 2;
      y7:=(y6-y5) div 2;
      //画 圆
      img1.Canvas.Pen.Color:=clBlue;
      img1.Canvas.Brush.Color:=clWhite;
      img1.Canvas.Brush.Style:=bsClear;
      img1.Canvas.Ellipse(x1,y1,x2,y2);
      //画 水平分割线
      img1.Canvas.MoveTo(x3,y3);
      img1.Canvas.LineTo(x4,y4);
      //画 垂直分割线
      img1.Canvas.MoveTo(x5,y5);
      img1.Canvas.LineTo(x6,y6);  img1.Canvas.Pen.Color:=clBlack;
      img1.Canvas.Brush.Color:=clBlack;
      if ((x>x5) and (y>y5)) and ((x<x4)and(y<y4)) then//选择 第1区间时
      begin
        //4分之1个圆有一个封闭圆弧和一个等边三角形组成
        img1.Canvas.Chord(x1,y1,x2,y2,x4,y4,x5,y5);//画 封闭圆弧
        img1.Canvas.Polygon([Point(x5,y5),Point(x7,y7),Point(x4,y4)]);//画 三角形
      end;
      if ((x>x1) and (y>y1)) and ((x<x7)and(y<y7)) then//选择 第2区间
      begin
        img1.Canvas.Chord(x1,y1,x2,y2,x5,y5,x3,y3);
        img1.Canvas.Polygon([Point(x5,y5),Point(x3,y3),Point(x7,y7)]);
      end;
      if ((x>x3) and (y>y3)) and ((x<x6)and(y<y6)) then//选择 第3区间
      begin
        img1.Canvas.Chord(x1,y1,x2,y2,x3,y3,x6,y6);
        img1.Canvas.Polygon([Point(x3,y3),Point(x6,y6),Point(x7,y7)]);
      end;
      if ((x>x7) and (y>y7)) and ((x<x2)and(y<y2)) then//选择 第4区间
      begin
        img1.Canvas.Chord(x1,y1,x2,y2,x6,y6,x4,y4);
        img1.Canvas.Polygon([Point(x6,y6),Point(x4,y4),Point(x7,y7)]);
      end;end;
      

  4.   


    打印可以使用TPrinter对象 将image打印,打印我没试,你可以试验一下。