splitContainer控件的中间那个分割线(竖线)位置能通过代码控制么?

ximomomoxinei28 2012-01-16 03:55:55
splitContainer的左侧是个dataGridview 右侧是Gridview选择某行后的详细信息。

一般情况下splitContainer右侧部分我希望是隐藏的(既缩进去),
当用户想看到splitContainer右侧的时候可以点击某个按钮来使splitContainer控件中间的竖线移动到适当的位置,这样右侧就显示出来了。

PS:其实如果能在竖线位置有个“小箭头”之类的,点击一下小箭头就显示出来,再点击一次就伸缩进去 这种效果是最棒的,可惜貌似winform原生态控件不支持这个功能吧,不打算用第三方控件
...全文
613 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ximomomoxinei34 2012-01-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 gomoku 的回复:]
可以设置SplitContainer的SplitterDistance属性:


C# code

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void splitCheck_CheckedChan……
[/Quote]
非常感谢!!帖子在之前结了 额。。。
gomoku 2012-01-16
  • 打赏
  • 举报
回复
可以设置SplitContainer的SplitterDistance属性:


public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void splitCheck_CheckedChanged(object sender, EventArgs e)
{
float target = this.splitCheck.Checked ? 10 : 150;
float current = this.splitContainer1.SplitterDistance;

const int frames = 20;
float step = (target - current) / frames;

for (int i = 0; i < frames; i++)
{
current += step;
this.splitContainer1.SplitterDistance = (int)current; //<--
Application.DoEvents();
}
}
}



partial class Form1
{
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.splitCheck = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.splitContainer1.Panel1.Controls.Add(this.splitCheck);
this.splitContainer1.Panel1MinSize = 10;
this.splitContainer1.Size = new System.Drawing.Size(442, 323);
this.splitContainer1.SplitterDistance = 150;
//
// splitCheck
//
this.splitCheck.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.splitCheck.Appearance = System.Windows.Forms.Appearance.Button;
this.splitCheck.Location = new System.Drawing.Point(138, 85);
this.splitCheck.Size = new System.Drawing.Size(10, 123);
this.splitCheck.UseVisualStyleBackColor = true;
this.splitCheck.CheckedChanged += new System.EventHandler(this.splitCheck_CheckedChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(442, 323);
this.Controls.Add(this.splitContainer1);
this.ResumeLayout(false);
}

private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.CheckBox splitCheck;
}
ximomomoxinei28 2012-01-16
  • 打赏
  • 举报
回复
OK thnks!!!!
bdmh 2012-01-16
  • 打赏
  • 举报
回复
第三方的,或者自定义一个吧(这个最好玩,DIY)

110,524

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧