2011-12-09 179 views
0

我想要加載圖像(例如在面板中)並使用我擁有的函數調用picture_by的邊緣並繪製通過點擊一個按鈕,在圖像邊緣的線條。然後,我想通過使用鼠標在同一圖像上畫出額外的線條。我還希望能夠通過鼠標擦除畫線,而不會稍後擦除圖像。 我不知道我應該在每種情況下使用哪個函數。一種方法可能是我用我的圖像設置面板的backgroundImage,並使用繪圖函數繪製exta行_drawn由mouse.if我使用此方法,然後我應該使用哪個函數通過單擊按鈕來繪製edges_drawn行?有沒有更好的辦法?請指導我。提前感謝。加載圖像,通過單擊按鈕在其上繪製圖形,通過鼠標在其上繪製線條

+0

什麼用段落下劃線了?這不是C#,對吧? :)你在用什麼 - WinForms或WPF? – Nayan

+0

它是C#,我使用winforms,我只用它來解釋它之前的單詞。 –

回答

0

看到下面的代碼..hope這將幫助你

Point startPoint = new Point(); 
bool dragging = false; 

int testOne = 30; 
int testTwo = 30; 

private void pictureBox1_MouseMove(object sender, MouseEventArgs e) 
{ 
    if (dragging) 
    { 
     int diffX = (pictureBox1.PointToClient(e.Location).X - startPoint.X); 
     int diffY = (pictureBox1.PointToClient(e.Location).Y - startPoint.Y); 

     label9.Text = diffX.ToString(); //Works, shows desired result 
     label10.Text = diffY.ToString(); //also works fine 

     testOne = (testOne + diffX); //Issue here 
     testTwo = (testTwo + diffY); //and here 

     label11.Text = (testOne).ToString(); //Unexpected results output 
     label12.Text = (testTwo).ToString(); 
    } 
} 

private void pictureBox1_MouseDown(object sender, MouseEventArgs e) 
{ 
    if (!dragging) //Incase the mouse down was repeating, it's not 
    { 
     startPoint = pictureBox1.PointToClient(e.Location); 
     dragging = true; 
    } 
} 

private void pictureBox1_MouseUp(object sender, MouseEventArgs e) 
{ 
    if (dragging) 
     dragging = false; 
} 
+0

謝謝您的回答。我搜索的圖片框在繪圖的情況下是多餘的。這句話是真的嗎? –

相關問題