本文介绍了如何添加vscrollbar和hscroll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//-窗体具有一个flowLayoutPanel1一个fileopen对话框和1个按钮
//--form is having one flowLayoutPanel1 one fileopen dialog box and 1 button
private void Form1_Load(object sender, EventArgs e)
{
InitializeOpenFileDialog();
}
private void InitializeOpenFileDialog()
{
// Set the file dialog to filter for graphics files.
this.openFileDialog1.Filter =
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
"All files (*.*)|*.*";
// Allow the user to select multiple images.
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "My Image Browser";
}
private void selectFilesButton_Click(object sender, EventArgs e)
{
DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
// Read the files
foreach (String file in openFileDialog1.FileNames)
{
// Create a PictureBox.
try
{
PictureBox pb = new PictureBox();
Image loadedImage = Image.FromFile(file);
pb.Height = loadedImage.Height;
pb.Width = loadedImage.Width;
pb.Image = loadedImage;
flowLayoutPanel1.Controls.Add(pb);
}
catch (Exception ex)
{
// Could not load the image - probably related to Windows file system permissions.
MessageBox.Show("Cannot display the image: " + file.Substring(file.LastIndexOf('\\'))
+ ". You may not have permission to read the file, or " +
"it may be corrupt.\n\nReported error: " + ex.Message);
}
}
}
推荐答案
在某些程序中,FlowLayoutPanel可能会变得太小而无法显示所有控件.在这种情况下,可以将 AutoScroll 属性设置为True.当控件溢出封闭区域时,这将使 FlowLayoutPanel显示滚动条.
In some programs, the FlowLayoutPanel may end up being too small to show all the controls. In this case, you can set the AutoScroll property to True. This will make the FlowLayoutPanel display scrollbars when the controls overflow the enclosing area.
供您参考
FlowLayoutPanel类 [ ^ ]
FlowLayoutPanel示例 [ ^ ]
FlowLayoutPanel [ ^ ]
For your information
FlowLayoutPanel Class[^]
FlowLayoutPanel Examples[^]
FlowLayoutPanel[^]
这篇关于如何添加vscrollbar和hscroll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!