스택 오버플로 사용자. C# VS 2010 Windows Form 프로젝트에서 사용자가 만든 컨트롤을 런타임에 탭 페이지를 드래그 할 때 컨트롤 플리커와 관련된 문제가 있습니다. 다음 코드를 사용했습니다 :런타임에 드래그하는 동안 깜박임 제어
private void control_MouseMove(object sender, MouseEventArgs e)
{
if (isDragged)
{
Point newPoint = ((Control)sender).PointToScreen(new Point(e.X,
e.Y));
newPoint.Offset(ptOffset);
((Control)sender).Location = newPoint;
((Control)sender).Refresh();
}
}
private void control_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDragged = true;
Point ptStartPosition = ((Control)sender).PointToScreen(new
Point(e.X, e.Y));
ptOffset = new Point();
ptOffset.X = ((Control)sender).Location.X - ptStartPosition.X;
ptOffset.Y = ((Control)sender).Location.Y - ptStartPosition.Y;
}
else
{
isDragged = false;
}
}
private void control_MouseUp(object sender, MouseEventArgs e)
{
((Control)sender).Refresh();
isDragged = false;
}
private void createButton_PB_Click(object sender, EventArgs e)
{
int ctrlExists = 0;
string btnName = btnName_TB.Text;
foreach (Button button in tabControl1.SelectedTab.Controls)
{
if (button.Text == btnName)
{
ctrlExists = 1;
}
}
if (btnName_TB.Text != "" && ctrlExists == 0)
{
Button newButton = new Button();
newButton.Name = btnName.Replace(" ", String.Empty);
newButton.Name += "u";
newButton.Text = btnName;
tabControl1.SelectedTab.Controls.Add(newButton);
newButton.Left = 10;
newButton.Top = 420;
lastBtnClicked = newButton;
}
SetupClickEvents(tabControl1.SelectedTab);
}
그래서 문제는 버튼을 추가하고 런타임에 드래그 할 수 있다는 것입니다. 그러나, 내가 다른 Button을 추가하고 주위를 끌면 ... 그 일을 마치고 첫 번째 단추를 드래그하려고 다시 돌아 가면 해당 단추가 깜박이고 마치 모든 곳으로 이동하려고하는 것처럼 작동합니다. 때로는 사라집니다. 컨트롤이 탭 페이지 안에 있다는 사실과 관련이 있습니다. 아마도 "newPoint"변수를 제대로 계산하지 못하고 있습니다. 어떤 아이디어 야?