0
我的問題是,即使當我想要在panel_MouseMove()上移動我繪製的矩形時,所有這些矩形都會閃爍。 我並不是沒有爲什麼。 這裏是我的panel_MouseMove法碼:C#.Net 4.0 panel_MouseMove事件閃爍矩形
private void panel_MouseMove(object sender, MouseEventArgs e)
{
bool flag = false;
if (_guiParserMgr != null)
{
if (e.Button == MouseButtons.Left)
{
foreach (GuiModulModel gmm in _guiParserMgr.Moduls)
{
log.Debug("Modul: XPos:" + gmm.getXPos() + " YPos:" + gmm.getYPos() + " WidthPos:" + ((int)gmm.getXPos() + (int)gmm.getWidth()) + " HeightPos:" + ((int)gmm.getYPos() + (int)gmm.getHeight()));
if (flag == false)
{
foreach (GuiEntityModel gem in gmm.Entitys)
{
log.Debug("Entity: XPos:" + gem.getXPos() + " YPos:" + gem.getYPos() + " WidthPos:" + ((int)gem.getXPos() + (int)gem.getWidth()) + " HeightPos:" + ((int)gem.getYPos() + (int)gem.getHeight()));
if (gem.getXPos() < e.X && gem.getXPos() + gem.getWidth() > e.X && gem.getYPos() < e.X && gem.getYPos() + gem.getHeight() > e.Y)
{
// Increment rectangle-location by mouse-location delta.
gem.setXPos(e.X /*+ _firstPoint.X*/);
gem.setYPos(e.Y /*+ _firstPoint.Y*/);
// Re-calibrate on each move operation.
_firstPoint = new MovePoint { X = e.X, Y = e.Y };
//panel.Invalidate();
foreach (GuiFieldModel gfm in gem.Fields)
{
// Increment rectangle-location by mouse-location delta.
gfm.setXPos(e.X/*+ _firstPoint.X*/);
gfm.setYPos(e.Y + 15/*+ _firstPoint.Y*/);
// Re-calibrate on each move operation.
_firstPoint = new MovePoint { X = e.X, Y = e.Y };
//panel.Invalidate();
}
flag = true;
}
}
}
if (flag == false)
{
foreach (GuiEnumTypeModel getm in gmm.EnumTypes)
{
log.Debug("EnumType: XPos:" + getm.getXPos() + " YPos:" + getm.getYPos() + " WidthPos:" + ((int)getm.getXPos() + (int)getm.getWidth()) + " HeightPos:" + ((int)getm.getYPos() + (int)getm.getHeight()));
if (getm.getXPos() < e.X && getm.getXPos() + getm.getWidth() > e.X && getm.getYPos() < e.X && getm.getYPos() + getm.getHeight() > e.Y)
{
// Increment rectangle-location by mouse-location delta.
getm.setXPos(e.X /*+ _firstPoint.X*/);
getm.setYPos(e.Y /*+ _firstPoint.Y*/);
// Re-calibrate on each move operation.
_firstPoint = new MovePoint { X = e.X, Y = e.Y };
//panel.Invalidate();
flag = true;
}
}
}
if (flag == false)
{
foreach (GuiServiceModel gsm in gmm.Services)
{
log.Debug("Service: XPos:" + gsm.getXPos() + " YPos:" + gsm.getYPos() + " WidthPos:" + ((int)gsm.getXPos() + (int)gsm.getWidth()) + " HeightPos:" + ((int)gsm.getYPos() + (int)gsm.getHeight()));
if (gsm.getXPos() < e.X && gsm.getXPos() + gsm.getWidth() > e.X && gsm.getYPos() < e.X && gsm.getYPos() + gsm.getHeight() > e.Y)
{
// Increment rectangle-location by mouse-location delta.
gsm.setXPos(e.X /*+ _firstPoint.X*/);
gsm.setYPos(e.Y /*+ _firstPoint.Y*/);
// Re-calibrate on each move operation.
_firstPoint = new MovePoint { X = e.X, Y = e.Y };
//panel.Invalidate();
flag = true;
}
}
}
if (flag == false)
{
foreach (GuiWebMvcModel gwm in gmm.WebMvcs)
{
log.Debug("WebMVC: XPos:" + gwm.getXPos() + " YPos:" + gwm.getYPos() + " WidthPos:" + ((int)gwm.getXPos() + (int)gwm.getWidth()) + " HeightPos:" + ((int)gwm.getYPos() + (int)gwm.getHeight()));
if (gwm.getXPos() < e.X && gwm.getXPos() + gwm.getWidth() > e.X && gwm.getYPos() < e.X && gwm.getYPos() + gwm.getHeight() > e.Y)
{
// Increment rectangle-location by mouse-location delta.
gwm.setXPos(e.X /*+ _firstPoint.X*/);
gwm.setYPos(e.Y /*+ _firstPoint.Y*/);
// Re-calibrate on each move operation.
_firstPoint = new MovePoint { X = e.X, Y = e.Y };
//panel.Invalidate();
flag = true;
}
}
}
if (flag == false)
{
if (gmm.getXPos() < e.X && gmm.getXPos() + gmm.getWidth() > e.X && gmm.getYPos() < e.X && gmm.getYPos() + gmm.getHeight() > e.Y)
{
// Increment rectangle-location by mouse-location delta.
gmm.setXPos(e.X /*+ _firstPoint.X*/);
gmm.setYPos(e.Y /*+ _firstPoint.Y*/);
// Re-calibrate on each move operation.
_firstPoint = new MovePoint { X = e.X, Y = e.Y };
//panel.Invalidate();
flag = true;
}
}
panel.Invalidate();
}
}
}
}
請幫幫我! :D 謝謝:)
我有一個問題,怎麼會是你的圖片框是一個沒有無效媒體鏈接drawed()? 當我刪除我的panel.invalidate()行,然後想要移動我的矩形,矩形不會移動。 – ActedLasmiranda
@ActionLasmiranda這段代碼是在picturebox類本身寫入的:這是一個擴展PictureBox的控件。我將編輯我的代碼示例以使其更清晰。 –
好的,謝謝,你可能有一個例子,你畫了一個相當大的矩形? – ActedLasmiranda