為什麼實心圓不能變色 |
尚未結案
|
ggyyggy
一般會員 發表:1 回覆:1 積分:0 註冊:2004-05-09 發送簡訊給我 |
各位大大你們好小弟剛學c Builder想請教一下為什麼我的
colordialog無法配合變色,請好心人幫幫忙感激不盡
.h檔
bool m_bDraw class CShape { protected: TCanvas* m_pCanvas; TColor m_Color; int m_nWidth; public: CShape(TCanvas* pCanvas) {m_pCanvas = pCanvas;} virtual ~CShape() {} virtual void OnMouseMove(int,int)=0; virtual void OnMouseDown(int,int)=0; virtual void OnMouseUp(int,int)=0; }; class CEllipse1 : public CShape { public: POINT m_ptMove; POINT m_ptOrigin; public: CEllipse1(TCanvas* pCanvas):CShape(pCanvas) {} virtual ~CEllipse1() {} virtual void OnMouseMove(int,int); virtual void OnMouseDown(int,int); virtual void OnMouseUp(int,int); }; .CPP
void __fastcall TForm1::SpeedButton10Click(TObject *Sender)
{
delete m_pObj; m_pObj = new CEllipse1(Canvas);
}
void CEllipse1::OnMouseMove(int x,int y)
{
m_pCanvas->Pen->Color= Form1->Color;
m_pCanvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y);
m_ptMove.x = x;
m_ptMove.y = y;
m_pCanvas->Brush->Style = bsSolid;
m_pCanvas->Pen->Color = clRed;
m_pCanvas->Brush->Color = clRed;
m_pCanvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y);
m_pCanvas->Brush->Color = clWhite;
} void CEllipse1::OnMouseUp(int x,int y)
{
} void CEllipse1::OnMouseDown(int x,int y)
{
m_ptOrigin.x =m_ptMove.x = x; m_ptOrigin.y =m_ptMove.y = y;
}
|
anpino
版主 發表:31 回覆:477 積分:231 註冊:2003-01-02 發送簡訊給我 |
引言: 各位大大你們好小弟剛學c Builder想請教一下為什麼我的 colordialog無法配合變色,請好心人幫幫忙感激不盡1. colordialog? 你的程式碼沒這東西。 2.變色實做如下: POINT m_ptMove; POINT m_ptOrigin; bool bDraw = false; //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { bDraw = true; m_ptOrigin.x =m_ptMove.x = X; m_ptOrigin.y =m_ptMove.y = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if(!bDraw) return; Canvas->Pen->Color= Form1->Color; Canvas->Brush->Color = Form1->Color; Canvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y); m_ptMove.x = X; m_ptMove.y = Y; Canvas->Brush->Style = bsSolid; Canvas->Pen->Color = clRed; Canvas->Brush->Color = clRed; Canvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { bDraw = false; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if (ColorDialog1->Execute()) { Canvas->Pen->Color = ColorDialog1->Color; Canvas->Brush->Color = ColorDialog1->Color; Canvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y); } } //---------------------------------------------------------------------------以上, 請參考。 ------------------------------- 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D ------------------------------- |
ggyyggy
一般會員 發表:1 回覆:1 積分:0 註冊:2004-05-09 發送簡訊給我 |
如果加入那一段結果在ColorDialog1 會出現未定義好像要在.h那加一點東西耶
好難喔希望有人能幫我解解看這是利用網路抓來的程式修改的謝謝大家
void CEllipse1::OnMouseMove(int x,int y)
{
m_pCanvas->Pen->Color= Form1->Color;
m_pCanvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y);
m_ptMove.x = x;
m_ptMove.y = y;
m_pCanvas->Brush->Style = bsSolid;
m_pCanvas->Pen->Color = ColorDialog1->Color;<-----這個部分
m_pCanvas->Brush->Color = ColorDialog1->Color;;<-----這個部分
m_pCanvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y);
m_pCanvas->Brush->Color = clWhite;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (ColorDialog1->Execute())
{
m_pCanvas->Pen->Color = ColorDialog1->Color;
m_pCanvas->Brush->Color = ColorDialog1->Color;
m_pCanvas->Ellipse(m_ptOrigin.x,m_ptOrigin.y,m_ptMove.x,m_ptMove.y);
}
}
//--------------------------------------------------------------------
|
anpino
版主 發表:31 回覆:477 積分:231 註冊:2003-01-02 發送簡訊給我 |
引言: 如果加入那一段結果在ColorDialog1 會出現未定義好像要在.h那加一點東西耶這還不簡單, 開一個新application, 把ColorDialog加到form上,注意看header , 它多了 #include。把 #include加入你的header裡就好啦。 ------------------------------- 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D ------------------------------- 發表人 - anpino 於 2004/05/11 08:38:49 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |