控件"WeifenLuo.WinFormsUI.Docking"的使用--如何控制自动停靠窗口的大小问题

覃祖甘 2013-06-12 12:07:11
在使用这个控件的时候,估计大家都会碰到 这样一个问题,就是当窗口是自动隐藏的时候,好像出来的大小一般比实际的大,感觉不太美观,所以我想办法控制这个部局大小。

如果在程序使用过程中,操作人改变了布局样式,且想以后都继续保持那样的样式,用到SaveAsXml这个方法,可是有点问题解决不了,不知道大家能不能帮我解决。


同时,我也把我的源码粘上吧,方便大家帮我找问题。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace DockPanelTest
{
public partial class MainForm : Form
{
private Form1 f1 = new Form1();
private Form2 f2 = new Form2();
private Form3 f3 = new Form3();
public MainForm()
{
InitializeComponent();
}

private void MainForm_Load(object sender, EventArgs e)
{
f1.Show(dockPanel1);
f2.Show(dockPanel1);
f3.Show(dockPanel1);

string uiFile = Path.Combine(Application.StartupPath, "CustomUI.xml");
if (File.Exists(uiFile))
{
DeserializeDockContent ddContent = new DeserializeDockContent(GetContentFromPersistString);
dockPanel1.LoadFromXml(uiFile, ddContent);
}
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
dockPanel1.SaveAsXml(Path.Combine(Application.StartupPath, "CustomUI.xml"));
}

#region 加载布局
private IDockContent GetContentFromPersistString(string persistString)
{
try
{
if (persistString == typeof(Form1).ToString())
{
if (f1 == null)
{
return new Form1();
}
else
{
return f1;
}

}
if (persistString == typeof(Form2).ToString())
{
if (f2 == null)
{
return new Form2();
}
else
{
return f2;
}

}
if (persistString == typeof(Form3).ToString())
{
if (f3 == null)
{
return new Form3();
}
else
{
return f3;
}

}
}
catch (Exception ex)
{
Console.WriteLine(persistString);
}
throw new Exception();
}

#endregion
}
}

...全文
155 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Conmajia 2013-06-12
  • 打赏
  • 举报
回复
有个autohidewidth属性,设置为零点几(小于1)表示百分比,设置为几百(大于1)表示固定像素宽度。。
覃祖甘 2013-06-12
  • 打赏
  • 举报
回复

         f1.Show(dockPanel1);
            f2.Show(dockPanel1);
            f3.Show(dockPanel1);
 
            string uiFile = Path.Combine(Application.StartupPath, "CustomUI.xml");
            if (File.Exists(uiFile))
            {
                DeserializeDockContent ddContent = new DeserializeDockContent(GetContentFromPersistString);
                dockPanel1.LoadFromXml(uiFile, ddContent);
            }
的位置有点问题,我改变一下就好了,修正如下:

            string uiFile = Path.Combine(Application.StartupPath, "CustomUI.xml");
            if (File.Exists(uiFile))
            {
                DeserializeDockContent ddContent = new DeserializeDockContent(GetContentFromPersistString);
                dockPanel1.LoadFromXml(uiFile, ddContent);
            }
         f1.Show(dockPanel1);
            f2.Show(dockPanel1);
            f3.Show(dockPanel1);
 
这样就解决了,感谢,结贴了喔。

110,499

社区成员

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

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

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