我正在尝试制作一个自定义控件,以响应屏幕分辨率。
我的想法很简单。
要实现这一点,我必须能够移动TableLayoutPanel单元格中的控件。
所以,我正在尝试下面的代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void _btnMove_Click(object sender, EventArgs e)
{
tableLayoutPanel1.Height += 30;
tableLayoutPanel1.RowCount = 3;
tableLayoutPanel1.Controls.Add(flowLayoutPanel4, 0, 2);
tableLayoutPanel1.SetColumnSpan(flowLayoutPanel4, 2);
}
private void _btnRestore_Click(object sender, EventArgs e)
{
tableLayoutPanel1.Controls.Add(flowLayoutPanel4, 6, 0);
}
}
}看上去效果不错。

这是TableLayoutPanel的原始图像。
当我按下移动按钮时,

是的,tablelayoutpanel面板现在有3行,搜索和Excel按钮位于第3行。
现在我必须把它们恢复原状。

在这里,它似乎不太正常。
我试着把他们送到6科尔,0排的位置。
但它在另一个牢房里。
有人知道在哪里修吗?
发布于 2014-08-03 01:53:21
您需要逆转在_btnMove_Click方法中所做的一切。仍被设置为2的列跨度是导致其向下移动到第2行的原因。
private void _btnRestore_Click(object sender, EventArgs e)
{
tableLayoutPanel1.Height -= 30;
tableLayoutPanel1.RowCount = 2;
tableLayoutPanel1.SetColumnSpan(flowLayoutPanel1, 1);
tableLayoutPanel1.Controls.Add(flowLayoutPanel1, 6, 0);
}https://stackoverflow.com/questions/25100779
复制相似问题