6

WinForms SplitContainerを置き換えるために誰かが提案できる代替コントロールはありますか?SplitContainerが、選択されたときとドラッグされたときに、その奇妙な点線のストリップを表示する方法が好きではありません。マウスを上に移動するのではなく、ユーザーがドラッグしたときにパネルのサイズを変更し、スプリッターをドラッグしているときに点線のストリップが表示されないようにしたい。基本的に、ビスタのWindowsエクスプローラーでパネルのすべてのサイズ変更が行われる方法と同じです。

これは私が話している点線のことです:

スプリッター
(出典:bhslaughter.com

4

5 に答える 5

9

独自の分割コンテナUserControlを作成します。基本的には、2つのパネルをコントロール(左右のパネル用)にドロップし、それらの間のスペースをスプリッターにします。UserControl自体の小さなMouseDown、MouseMove、MouseUpロジックを使用すると、「スプリッター」を左右に簡単に移動できます。2つのパネルは、スプリッターを除くすべての場所でこれを適切にブロックするため、マウスがスプリッターは可能な限りシンプルです。

コントロールをデザインモードで希望どおりに動作させるのは、少し余分な作業になる可能性があります。

于 2010-04-23T20:10:08.610 に答える
6

あなたの質問を見た後にこれを見つけたので、共有したいと思いました: SplitContainer FAQ

そこにある2番目のリンクは、あなたが何をする必要があるかを正確に示しています。

リンクが切れた場合に備えて、そのテキストを次に示します。

//1.  Use the custom control defined in the SplitContainerNoFocus sample
//2. Insert the following code in your project, and attach these events to all of the SplitContainers that you don't want stealing focus.

// Temp variable to store a previously focused control
private Control focused = null; 

private void splitContainer_MouseDown(object sender, MouseEventArgs e)
{
   // Get the focused control before the splitter is focused
   focused = getFocused(this.Controls);
}

private Control getFocused(Control.ControlCollection controls)
{
   foreach (Control c in controls)
   {
      if (c.Focused)
      {
         // Return the focused control
         return c;
      }
      else if (c.ContainsFocus)
      {
         // If the focus is contained inside a control's children
         // return the child
         return getFocused(c.Controls);
      }
   }
   // No control on the form has focus
   return null;
}

private void splitContainer_MouseUp(object sender, MouseEventArgs e)
{
   // If a previous control had focus
   if (focused != null)
   {
      // Return focus and clear the temp variable for 
      // garbage collection
      focused.Focus();
      focused = null;
   }
}
于 2010-06-02T08:17:38.460 に答える
1

SplitContainerをいじくり回すことはできません。コントロールのサイズ変更にのみ使用している場合は、完全に削除することが1つの可能性です。代わりに、コントロール自体でマウスイベントを使用できます。TreeViewをフォームにドロップし、左側にドッキングします。MouseDown / Move / Upイベントをサブスクライブし、次のように記述します。

    bool mDragging;

    private bool onTreeEdge(Point pos) {
        return pos.X >= treeView1.DisplayRectangle.Right - 3;
    }
    private void treeView1_MouseMove(object sender, MouseEventArgs e) {
        treeView1.Cursor = mDragging || onTreeEdge(e.Location) ? Cursors.VSplit : Cursors.Default;
        if (mDragging) treeView1.Width = e.X;
    }
    private void treeView1_MouseDown(object sender, MouseEventArgs e) {
        mDragging = onTreeEdge(e.Location);
        if (mDragging) treeView1.Capture = true;
    }
    private void treeView1_MouseUp(object sender, MouseEventArgs e) {
        mDragging = false;
    }
于 2010-04-23T20:37:41.723 に答える
1

同じものが必要で、次のプロパティを設定しました。

        splitContainer1.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
        splitContainer1.Dock = DockStyle.Fill;
        splitContainer1.IsSplitterFixed = true;

お役に立てれば。

于 2010-07-23T18:08:43.700 に答える
-1

また、無料のKryptonツールキットに付属している分割コンテナコンポーネントもご覧ください。

于 2011-08-22T14:55:28.373 に答える