請問ComboBox繪圖(圖形發生重疊)問題??? |
尚未結案
|
Vincent2424
一般會員 ![]() ![]() 發表:57 回覆:40 積分:19 註冊:2004-12-15 發送簡訊給我 |
如果我使用矩形、圓形、正方形就可以正常切換到不同形狀,如下 void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{ TRect r;
r.Top = 0;
r.Left = 0;
r.Right = ListBox1->Width;
r.Bottom = ListBox1->Height;
ListBox1->Canvas->FillRect(r); if (ComboBox1->Text == "矩形")
ListBox1->Canvas->Rectangle(10, 10, 300, 100); else if (ComboBox1->Text == "圓形")
ListBox1->Canvas->Ellipse(10, 10, 100, 100); else if (ComboBox1->Text == "Arc")
ListBox1->Canvas->Arc(10, 10, 30, 30, 40, 40, 50, 50); else if (ComboBox1->Text == "正方形")
ListBox1->Canvas->Rectangle(10, 10, 200, 200); } 但是如果我加入Line的話,切到line再切到回到其他(如圓形、正方形),原本的line就不會消失,重疊到新圖上.....如下 void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{ TRect r;
r.Top = 0;
r.Left = 0;
r.Right = ListBox1->Width;
r.Bottom = ListBox1->Height;
ListBox1->Canvas->FillRect(r); if (ComboBox1->Text == "矩形")
ListBox1->Canvas->Rectangle(10, 10, 300, 100); else if (ComboBox1->Text == "圓形")
ListBox1->Canvas->Ellipse(10, 10, 100, 100); else if (ComboBox1->Text == "Arc")
ListBox1->Canvas->Arc(10, 10, 30, 30, 40, 40, 50, 50); else if (ComboBox1->Text == "正方形")
ListBox1->Canvas->Rectangle(10, 10, 200, 200); else if (ComboBox1->Text == "Line")
//Upper surface
ListBox1->Canvas->MoveTo(0,75);
ListBox1->Canvas->LineTo(3.125,68.9);
ListBox1->Canvas->LineTo(6.25,66.525);
ListBox1->Canvas->LineTo(12.5,63.175);
ListBox1->Canvas->LineTo(18.75,60.6);
ListBox1->Canvas->LineTo(25 ,58.525);
ListBox1->Canvas->LineTo(37.5,55.275);
ListBox1->Canvas->LineTo(50 ,53);
ListBox1->Canvas->LineTo(62.5,51.475);
ListBox1->Canvas->LineTo(75 ,50.6); }
請問我該怎麼解決圖形重疊的問題呢
|
jow
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
|
jow
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
|
Vincent2424
一般會員 ![]() ![]() 發表:57 回覆:40 積分:19 註冊:2004-12-15 發送簡訊給我 |
|
jow
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
建議將繪圖用的TListBox換成
TPaintBox(System Page下的項目).
void __fastcall TForm1::ComboBox1Change(TObject *Sender) { //Draw Background PaintBox1->Canvas->Brush->Color = Color; PaintBox1->Canvas->FillRect(PaintBox1->ClientRect); PaintBox1->Canvas->Pen->Color = clRed; if (ComboBox1->Text == "矩形") PaintBox1->Canvas->Rectangle(10, 10, 300, 100); else if (ComboBox1->Text == "圓形") PaintBox1->Canvas->Ellipse(10, 10, 100, 100); else if (ComboBox1->Text == "Arc") PaintBox1->Canvas->Arc(10, 10, 30, 30, 40, 40, 50, 50); else if (ComboBox1->Text == "正方形") PaintBox1->Canvas->Rectangle(10, 10, 200, 200); else if (ComboBox1->Text == "Line") { //Upper surface PaintBox1->Canvas->MoveTo(0,75); PaintBox1->Canvas->LineTo(3.125,68.9); PaintBox1->Canvas->LineTo(6.25,66.525); PaintBox1->Canvas->LineTo(12.5,63.175); PaintBox1->Canvas->LineTo(18.75,60.6); PaintBox1->Canvas->LineTo(25 ,58.525); PaintBox1->Canvas->LineTo(37.5,55.275); PaintBox1->Canvas->LineTo(50 ,53); PaintBox1->Canvas->LineTo(62.5,51.475); PaintBox1->Canvas->LineTo(75 ,50.6); } } |
Vincent2424
一般會員 ![]() ![]() 發表:57 回覆:40 積分:19 註冊:2004-12-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |