gpt4 book ai didi

c# - 动态改变面板的大小

转载 作者:太空狗 更新时间:2023-10-29 20:15:16 24 4
gpt4 key购买 nike

我正在实现一个需要在面板中拖放图像框的应用程序。图像框是从程序中动态添加的,因此我在面板中将自动滚动属性设置为 true。但是当我拖出图像框时面板底部的面板尺寸减小了。我在面板中设置了 autosize 属性 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);
}

这是包含面板的窗体的构造函数。加载时,必须将图片框添加到面板,并实现面板的拖放事件。

请帮帮我..

最佳答案

除非我在代码中以编程方式设置最大宽度,否则我无法让它工作。设计器中的最大宽度是多少(或者是否设置了最大宽度)并不重要。

int newWidth = 200;
panel.MaximumSize = new Size(newWidth, panel.Height);
panel.Size = new Size(newWidth, panel.Height);

关于c# - 动态改变面板的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2414377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com