패널에서 이미지 상자를 드래그 앤 드롭해야하는 응용 프로그램을 구현 중입니다. 이미지 상자가 프로그램에서 동적으로 추가되어 패널에서 autoscroll 속성을 true로 설정했습니다. 그러나 패널 크기가 줄어든 패널의 아래쪽 상자를 드래그했습니다. 패널에 자동 크기 조정 false 속성을 넣었습니다. 패널이 다른 패널에 도킹되어 있습니다. 런타임에 패널 크기를 설정하고 싶습니다. 어떻게하면됩니까? 이.패널의 크기를 동적으로 변경하십시오.
public form1(int[,] dummy, int columnSize, int rowSize)
{
this.dummy= dummy;
numOfColumns = columnSize;
numOfRows = rowSize;
getData();
addIds = addIdArray;
data = mylist;
InitializeComponent();
//panel1.MinimumSize = new Size(columnSize * 40, rowSize * 40);
//panel1.Height = rowSize * 40;
//panel1.Width = columnSize * 40;
//panel4.Height = rowSize * 40;
//panel4.Width = columnSize * 40;
int x, y;
Structures.EmptyRectSpace space = new Structures.EmptyRectSpace();
for (int i = 0; i < data.Count; i++)// set picture boxes
{
space = (Structures.EmptyRectSpace)data[i];
x = space.startingJ;
y = space.startingI;
int h, w;
h = space.length;
w = space.width;
p = new PictureBox();
p.Width = w * 40;
p.Height = h * 40;
p.BackColor = Color.DarkGreen;
p.Image = Properties.Resources.v;
p.BorderStyle = BorderStyle.FixedSingle;
p.Name = addIdArray[i].ToString();
p.Location = new Point((x + 1 - w) * 40, (y + 1 - h) * 40);
this.panel1.Controls.Add(p);
}
foreach (Control c in this.panel1.Controls)
{
if (c is PictureBox)
{
c.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
}
}
this.panel1.DragOver += new System.Windows.Forms.DragEventHandler(this.panel1_DragOver);
panel1.DragOver += new DragEventHandler(panel1_DragOver);
panel1.DragDrop += new DragEventHandler(panel1_DragDrop);
panel1.AllowDrop = true;
panel2.AllowDrop = true;
foreach (Control c in this.panel2.Controls)
{
c.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
}
this.panel2.DragOver += new System.Windows.Forms.DragEventHandler(this.panel2_DragOver);
panel2.DragOver += new DragEventHandler(panel2_DragOver);
panel2.DragDrop += new DragEventHandler(panel2_DragDrop);
}
이것은 패널이 포함 된 양식의 생성자입니다. 로드 할 때 그림 상자를 패널에 추가해야하며 패널의 끌어 놓기 이벤트가 구현되어야합니다.
나에게 도움의 손길을주세요 ..
이 웹, WinForm 또는 WCF/Silverlight입니까? 사용중인 실제 컨트롤 클래스는 무엇입니까? 크기를 한 번만 설정한다고 말하고 있습니까? – Blanthor
아주 적절한 질문! 나는 이것이 Windows Form에 있다고 가정했다 ... –
몇 가지 제안 사항 : 응용 프로그램 생성자 외부에서 초기 항목 (* int [,] dummy, int columnSize, int rowSize *)을 이동하고 모든 초기화 및 작업 * 'InitializeComponent()'- 그렇지 않으면 일부 데이터가 유효하지 않은 데이터로 초기화 될 수 있습니다. – jp2code