如果Autoscroll激活,则更正Splitcontainer Panelsize [英] Correct Splitcontainer Panelsize if Autoscroll gets active

查看:110
本文介绍了如果Autoscroll激活,则更正Splitcontainer Panelsize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我在过去几年偶然发现了一个令人讨厌的问题,但却没有找到令人满意的设计模式。

简化:我在Panel1中的水平SplitContainer中有一个按钮(Panel1就像一个工具条)。

我设置Panel1.Autoscroll为true(因为我需要查看所有的按钮)

如果我调整我的表格更小,使按钮不完全可见,滚动条出现我打算,但我只能看到我的按钮的上半部分,因为水平滚动条几乎耗尽了我的panel1的所有空间。

我想要的是,一旦滚动条出现,splitcontainer的Panel1会随着滚动条的宽度增长,并且一旦消失就会收缩。

所以实际上像 Horizo​​ntalScrollBarAndAutoGrow = true; 在splitcontainer.Panel1上。

是否有任何简单的解决方案设计splitcontainer为此,或有有人派出了具有该功能的拆分容器吗?



使用工具条有时候不是一种选择。



非常感谢!





使用此InitializeComponent的新Winforms应用程序()



  private   void  InitializeComponent()
{
this .splitContainer1 = new System.Windows.Forms.SplitContainer();
this .button1 = new System.Windows.Forms.Button();
//
// splitContainer1
//
this .splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this .splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizo​​ntal;
//
// splitContainer1.Panel1
//
this .splitContainer1.Panel1.AutoScroll = true ;
this .splitContainer1.Panel1.Controls.Add( this .button1);
this .splitContainer1.Size = new System.Drawing.Size( 159 217 );
.splitContainer1.SplitterDistance = 29 ;
this .splitContainer1.TabIndex = 0 ;
//
// button1
//
this .button1.Location = new System.Drawing.Point( 29 4 );
this .button1.Size = new System.Drawing.Size( 117 23 );
this .button1.TabIndex = 0 ;
this .button1.Text = button1
//
// Form1
//
this .AutoScaleDimensions = new System.Drawing.SizeF (6F,13F);
this .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this .ClientSize = new System.Drawing.Size( 159 217 );
this .Controls.Add( this .splitContainer1);
this .splitContainer1.Panel1.ResumeLayout( false );
}
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.Button button1;

解决方案

< blockquote>据我所知,那里没有类似的东西。

但是......这应该不难:只需处理面板的Resized事件,并检查宽度。如果低于最小值,则移动分离器将面板高度设置为大模式。如果它在上面,那么将拆分器设置为小模式



您可能需要进行一些检查以查看您所处的模式以避免Resize事件始终触发一个新的Resize事件,但这非常简单。


Hi there,

I've stumbled over an quite annoying problem in the last years and yet haven't found a satisfying design pattern for that problem.
Simplified: I have a button in a horizontal SplitContainer in Panel1 (Panel1 acts like a toolstrip).
I set Panel1.Autoscroll true (because i _need_ to see all the button)
if i resize my form smaller, so that the button is not completely visible, a scrollbar appears as I intend to, but i can only see the upper half of my button, because the horizontal scrollbar eats up almost all of the space of my panel1.
What I want is, that Panel1 of the splitcontainer grows by the width of the scrollbar as soon as the scrollbar appears and shrinks as soon as it disappears.
so actually somthing like HorizontalScrollBarAndAutoGrow = true; on splitcontainer.Panel1.
Is there any simple solution by design of splitcontainer for that, or has anyone derived a splitcontainer with that functionality?

Using toolstrip is sometimes not an option.

Thanks alot!


New Winforms App with this InitializeComponent()

private void InitializeComponent()
{
    this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    this.button1 = new System.Windows.Forms.Button();
    //
    // splitContainer1
    //
    this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
    //
    // splitContainer1.Panel1
    //
    this.splitContainer1.Panel1.AutoScroll = true;
    this.splitContainer1.Panel1.Controls.Add(this.button1);
    this.splitContainer1.Size = new System.Drawing.Size(159, 217);
    this.splitContainer1.SplitterDistance = 29;
    this.splitContainer1.TabIndex = 0;
    //
    // button1
    //
    this.button1.Location = new System.Drawing.Point(29, 4);
    this.button1.Size = new System.Drawing.Size(117, 23);
    this.button1.TabIndex = 0;
    this.button1.Text = "button1"
    //
    // Form1
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(159, 217);
    this.Controls.Add(this.splitContainer1);
    this.splitContainer1.Panel1.ResumeLayout(false);
}
  private System.Windows.Forms.SplitContainer splitContainer1;
  private System.Windows.Forms.Button button1;

解决方案

As far as I know, there is nothing like that out there.
But...it shouldn't be difficult to do: just handle the Resized event for the panel, and check the width. If it's below your minimum, then move the splitter to set the panel height to "large mode". If it's above, then set the splitter to "small mode"

You might have to do some checking to see what mode you are in to avoid the Resize event always triggering a new Resize event, but that's pretty trivial.


这篇关于如果Autoscroll激活,则更正Splitcontainer Panelsize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆