我有一个创建的面板。 这有autoscroll = true
在开始时,我添加了6个256x256图像盒。 我存储最后一个picturebox的位置,这样我就知道在哪里放置一个新的picturebox。
我还在面板的右上方添加了一个picturebox(位置(8744,8744)),以便面板可以伸展到9000px。
稍后当我在面板中滚动时,我可以按下按钮并将面板添加到面板。 问题是,当我设置图片框的位置并将其添加到面板时,它在视觉上完全错误。
添加更多图片的代码。
private void addPictureBox(Point pixelCoordinates, Bitmap image) { PictureBox pNewImage = new PictureBox(); imagePanel.Controls.Add(pNewImage); pNewImage.Image = image; pNewImage.Name = "image_:" + pixelCoordinates.X + "_" + pixelCoordinates.Y; pNewImage.Location = pixelCoordinates; pNewImage.Size = new System.Drawing.Size(256, 256); pNewImage.Visible = true; pNewImage.BackColor = Color.White; imagePanel.Update(); }如果我调试并观察面板,它会说新的图片盒具有我设置的位置,但从外观上看,它不是。
我注意到这是真正发生的事情:picturebox的位置来自我滚动的位置+ location.X。
任何人都知道我该如何解决这个问题?
提前致谢。
I have a created a panel. This has autoscroll = true
At the start i added 6 pictureboxes that are 256x256 with images. I store the last picturebox location, so that i know where to put a new picturebox.
I also add a picturebox to the upper right of the panel(location(8744,8744)), so that the panel will stretch to 9000px.
Later on when i scroll around in the panel, i can push a button and add a picturebox to the panel. The problem is that when i set the location of the picturebox and add it to the panel, it comes out totally wrong, visually.
Code for adding more images.
private void addPictureBox(Point pixelCoordinates, Bitmap image) { PictureBox pNewImage = new PictureBox(); imagePanel.Controls.Add(pNewImage); pNewImage.Image = image; pNewImage.Name = "image_:" + pixelCoordinates.X + "_" + pixelCoordinates.Y; pNewImage.Location = pixelCoordinates; pNewImage.Size = new System.Drawing.Size(256, 256); pNewImage.Visible = true; pNewImage.BackColor = Color.White; imagePanel.Update(); }If i debug and watches the panel, it says that the new picturebox has the location i set, but visually, it's not.
I have noticed that this is what really happens: The location of the picturebox is from where i have scrolled + location.X.
Anyone got an idea how i can fix this?
Thanks in advance.
最满意答案
如果在滚动离开坐标0,0之后添加了图片框,则可能需要通过将滚动量添加到pixelCoordinates来解决此问题。 在您的计算中尝试使用imagePanel.VerticalScroll.Value和imagePanel.HorizontalScroll.Value 。
If the pictureboxes are being added after you have scrolled away from the coordinates 0,0 you may need to account for this by adding the scroll amount to pixelCoordinates. Try using imagePanel.VerticalScroll.Value and imagePanel.HorizontalScroll.Value in your calculations.
更多推荐
发布评论