FormLayoutPanel,使用 LinkLabel 时不改变方向
FormLayoutPanel, Not Changing Direction when using LinkLabels
我正在尝试将 FlowLayoutPanel 与 Visual Studio 中的 linkLabels 一起用于快速项目。我选择 "TopDown" 作为方向并换行为 false。当我启动程序时;但是,方向总是从左到右。是否有我没有检查过的盒子或其他东西?或者是否有任何原因导致链接标签会忽略流向?
这是我的代码和我看到的一些屏幕截图。
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 myProject
{
public partial class Form1 : Form
{
FlowLayoutPanel panel = new FlowLayoutPanel();
public Form1()
{
InitializeComponent();
linkLabel1.LinkClicked += linkLabel1_LinkClicked;
linkLabel2.LinkClicked += linkLabel2_LinkClicked;
linkLabel3.LinkClicked += linkLabel3_LinkClicked;
Controls.Add(panel);
panel.Controls.Add(linkLabel1);
panel.Controls.Add(linkLabel2);
panel.Controls.Add(linkLabel3);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel.Controls.SetChildIndex(linkLabel1, 0);
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel.Controls.SetChildIndex(linkLabel2, 0);
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel.Controls.SetChildIndex(linkLabel3, 0);
}
}
}
这是我启动程序之前的控制视图。
这是我在 运行 程序时看到的 - 用红色箭头标记。
因为您正在代码隐藏中初始化 FlowLayoutPanel,所以您必须在同一代码隐藏中设置 FlowLayoutPanel 的这个新实例的 FlowDirection 属性:
FlowLayoutPanel panel = new FlowLayoutPanel();
public Form1()
{
InitializeComponent();
panel.FlowDirection = FlowDirection.TopDown;
您在代码隐藏中声明的 FlowLayoutPanel 与布局中的 FlowLayoutPanel 是分开的,因此 FlowDirection 属性 设置不同。我测试了上面的代码,我相信它可以满足您的需求。
我正在尝试将 FlowLayoutPanel 与 Visual Studio 中的 linkLabels 一起用于快速项目。我选择 "TopDown" 作为方向并换行为 false。当我启动程序时;但是,方向总是从左到右。是否有我没有检查过的盒子或其他东西?或者是否有任何原因导致链接标签会忽略流向?
这是我的代码和我看到的一些屏幕截图。
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 myProject
{
public partial class Form1 : Form
{
FlowLayoutPanel panel = new FlowLayoutPanel();
public Form1()
{
InitializeComponent();
linkLabel1.LinkClicked += linkLabel1_LinkClicked;
linkLabel2.LinkClicked += linkLabel2_LinkClicked;
linkLabel3.LinkClicked += linkLabel3_LinkClicked;
Controls.Add(panel);
panel.Controls.Add(linkLabel1);
panel.Controls.Add(linkLabel2);
panel.Controls.Add(linkLabel3);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel.Controls.SetChildIndex(linkLabel1, 0);
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel.Controls.SetChildIndex(linkLabel2, 0);
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel.Controls.SetChildIndex(linkLabel3, 0);
}
}
}
这是我启动程序之前的控制视图。
这是我在 运行 程序时看到的 - 用红色箭头标记。
因为您正在代码隐藏中初始化 FlowLayoutPanel,所以您必须在同一代码隐藏中设置 FlowLayoutPanel 的这个新实例的 FlowDirection 属性:
FlowLayoutPanel panel = new FlowLayoutPanel();
public Form1()
{
InitializeComponent();
panel.FlowDirection = FlowDirection.TopDown;
您在代码隐藏中声明的 FlowLayoutPanel 与布局中的 FlowLayoutPanel 是分开的,因此 FlowDirection 属性 设置不同。我测试了上面的代码,我相信它可以满足您的需求。