2014-01-19 36 views
0

這是用繪製一個矩形在pictureBox1代碼IM:如何使用鼠標滾輪放大繪製的矩形區域進行縮放?

private void DrawRectangle(Graphics e) 
{ 
    using (Pen pen = new Pen(Color.Red, 2)) 
    { 
     e.DrawRectangle(pen, mRect); 
    } 
} 

private void pictureBox1_MouseDown(object sender, MouseEventArgs e) 
{ 
    mRect = new Rectangle(e.X, e.Y, 0, 0); 
    pictureBox1.Invalidate(); 
} 


private void pictureBox1_MouseMove(object sender, MouseEventArgs e) 
{ 
    if (e.Button == MouseButtons.Left) 
    { 
     mRect = new Rectangle(mRect.Left, mRect.Top, e.X - mRect.Left, e.Y - mRect.Top); 
     pictureBox1.Invalidate(); 
    } 
} 

如何使我對以後的drawed長方形當我移動鼠標滾輪向上或向下將調整對所繪製的矩形區域在pictureBox1中的圖像? 不調整所有圖像的大小,但僅對矩形繪製區域進行放大/縮小。

回答

0

熟悉MouseWheel事件。

0

鼠標滾輪事件可以手動添加如下圖所示,當然也可以將其設置爲你需要:

this.MouseWheel += new MouseEventHandler(Form1_MouseWheel); 

private void Form1_MouseWheel(object sender, MouseEventArgs e) 
{ 
    e.Delta; 
    // e.Delta: Represents the amount the wheel has changed. This value is positive if the mouse wheel is 
    // rotated in an upward direction (away from the user) or negative if the mouse wheel 
    // is rotated in a downward direction (toward the user). 
} 

可以使用Graphics類的ScaleTransform來擴展您繪製的矩形。

相關問題