关于winform浮动窗口

孫大聖 2012-03-05 09:34:02
RT:
把form分成2部分,
左边是导航的,
右边是显示内容。
如何实现左边框的浮动。可以显示和隐藏。
先在这谢谢了。
...全文
485 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
buyong 2012-03-05
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.SplitContainer splitContainer2;
private System.Windows.Forms.ListView listView2;
private System.Windows.Forms.ListView listView1;

public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
splitContainer1 = new System.Windows.Forms.SplitContainer();
treeView1 = new System.Windows.Forms.TreeView();
splitContainer2 = new System.Windows.Forms.SplitContainer();
listView1 = new System.Windows.Forms.ListView();
listView2 = new System.Windows.Forms.ListView();
splitContainer1.SuspendLayout();
splitContainer2.SuspendLayout();
SuspendLayout();

// Basic SplitContainer properties.
// This is a vertical splitter that moves in 10-pixel increments.
// This splitter needs no explicit Orientation property because Vertical is the default.
splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
splitContainer1.ForeColor = System.Drawing.SystemColors.Control;
splitContainer1.Location = new System.Drawing.Point(0, 0);
splitContainer1.Name = "splitContainer1";
// You can drag the splitter no nearer than 30 pixels from the left edge of the container.
splitContainer1.Panel1MinSize = 30;
// You can drag the splitter no nearer than 20 pixels from the right edge of the container.
splitContainer1.Panel2MinSize = 20;
splitContainer1.Size = new System.Drawing.Size(292, 273);
splitContainer1.SplitterDistance = 79;
// This splitter moves in 10-pixel increments.
splitContainer1.SplitterIncrement = 10;
splitContainer1.SplitterWidth = 6;
// splitContainer1 is the first control in the tab order.
splitContainer1.TabIndex = 0;
splitContainer1.Text = "splitContainer1";
// When the splitter moves, the cursor changes shape.
splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(splitContainer1_SplitterMoved);
splitContainer1.SplitterMoving += new System.Windows.Forms.SplitterCancelEventHandler(splitContainer1_SplitterMoving);

// Add a TreeView control to the left panel.
splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.Control;
// Add a TreeView control to Panel1.
splitContainer1.Panel1.Controls.Add(treeView1);
splitContainer1.Panel1.Name = "splitterPanel1";
// Controls placed on Panel1 support right-to-left fonts.
splitContainer1.Panel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;


// Add a SplitContainer to the right panel.
splitContainer1.Panel2.Controls.Add(splitContainer2);
splitContainer1.Panel2.Name = "splitterPanel2";

// This TreeView control is in Panel1 of splitContainer1.
treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
treeView1.ForeColor = System.Drawing.SystemColors.InfoText;
treeView1.ImageIndex = -1;
treeView1.Location = new System.Drawing.Point(0, 0);
treeView1.Name = "treeView1";
treeView1.SelectedImageIndex = -1;
treeView1.Size = new System.Drawing.Size(79, 273);
// treeView1 is the second control in the tab order.
treeView1.TabIndex = 1;

// Basic SplitContainer properties.
// This is a horizontal splitter whose top and bottom panels are ListView controls. The top panel is fixed.
splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
// The top panel remains the same size when the form is resized.
splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
splitContainer2.Location = new System.Drawing.Point(0, 0);
splitContainer2.Name = "splitContainer2";
// Create the horizontal splitter.
splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
splitContainer2.Size = new System.Drawing.Size(207, 273);
splitContainer2.SplitterDistance = 125;
splitContainer2.SplitterWidth = 6;
// splitContainer2 is the third control in the tab order.
splitContainer2.TabIndex = 2;
splitContainer2.Text = "splitContainer2";

// This splitter panel contains the top ListView control.
splitContainer2.Panel1.Controls.Add(listView1);
splitContainer2.Panel1.Name = "splitterPanel3";

// This splitter panel contains the bottom ListView control.
splitContainer2.Panel2.Controls.Add(listView2);
splitContainer2.Panel2.Name = "splitterPanel4";

// This ListView control is in the top panel of splitContainer2.
listView1.Dock = System.Windows.Forms.DockStyle.Fill;
listView1.Location = new System.Drawing.Point(0, 0);
listView1.Name = "listView1";
listView1.Size = new System.Drawing.Size(207, 125);
// listView1 is the fourth control in the tab order.
listView1.TabIndex = 3;

// This ListView control is in the bottom panel of splitContainer2.
listView2.Dock = System.Windows.Forms.DockStyle.Fill;
listView2.Location = new System.Drawing.Point(0, 0);
listView2.Name = "listView2";
listView2.Size = new System.Drawing.Size(207, 142);
// listView2 is the fifth control in the tab order.
listView2.TabIndex = 4;

// These are basic properties of the form.
ClientSize = new System.Drawing.Size(292, 273);
Controls.Add(splitContainer1);
Name = "Form1";
Text = "Form1";
splitContainer1.ResumeLayout(false);
splitContainer2.ResumeLayout(false);
ResumeLayout(false);
}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void splitContainer1_SplitterMoving(System.Object sender, System.Windows.Forms.SplitterCancelEventArgs e)
{
// As the splitter moves, change the cursor type.
Cursor.Current = System.Windows.Forms.Cursors.NoMoveVert;
}
private void splitContainer1_SplitterMoved(System.Object sender, System.Windows.Forms.SplitterEventArgs e)
{
// When the splitter stops moving, change the cursor back to the default.
Cursor.Current=System.Windows.Forms.Cursors.Default;
}
}
馒头仔 2012-03-05
  • 打赏
  • 举报
回复
楼主的意思是想做类似于浏览器的收藏侧边栏,可以隐藏或者显示吧,我也研究过一段时间,没发现什么好的方法
maochenai 2012-03-05
  • 打赏
  • 举报
回复
form本身在.net里面用托管语言应该无法分割的吧。。。你可以用两个form,排好它们的位置,利用hide,show来控制。。
孫大聖 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 llwinnner 的回复:]

引用 13 楼 qust_sunfei 的回复:
引用 11 楼 chinajiyong 的回复:

用splitContainer控件可以实现


好的。我想在2个panel中间或者边框上点一下折叠,再点一下就显示

弄个按钮,点击的时候设置一下宽度就行了。
[/Quote]

这个试过。但是不太美观。我再看下吧。一会儿结贴、谢谢了
深海之蓝 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 qust_sunfei 的回复:]
引用 11 楼 chinajiyong 的回复:

用splitContainer控件可以实现


好的。我想在2个panel中间或者边框上点一下折叠,再点一下就显示
[/Quote]
弄个按钮,点击的时候设置一下宽度就行了。
孫大聖 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 chinajiyong 的回复:]

用splitContainer控件可以实现
[/Quote]

好的。我想在2个panel中间或者边框上点一下折叠,再点一下就显示
happytonice 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 chinajiyong 的回复:]

用splitContainer控件可以实现
[/Quote]
+
EnForGrass 2012-03-05
  • 打赏
  • 举报
回复
用splitContainer控件可以实现
孫大聖 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 bdmh 的回复:]

splitContainer,就可以了
[/Quote]
好的。我试下。
孫大聖 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 buyong 的回复:]

C# code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form
{
……
[/Quote]

辛苦了。。
孫大聖 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kkxxllasasas 的回复:]

http://www.cyqdata.com/cnblogs/article-detail-3170
[/Quote]

好的。谢谢了。
bdmh 2012-03-05
  • 打赏
  • 举报
回复
splitContainer,就可以了
孫大聖 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 maochenai 的回复:]

form本身在.net里面用托管语言应该无法分割的吧。。。你可以用两个form,排好它们的位置,利用hide,show来控制。。
[/Quote]

可以加个动画,对吧?
孫大聖 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 llyyqq123 的回复:]

楼主的意思是想做类似于浏览器的收藏侧边栏,可以隐藏或者显示吧,我也研究过一段时间,没发现什么好的方法
[/Quote]

对的。可以左右折叠的。

110,538

社区成员

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

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

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