Split Container SplitterDistance无需用户干预即可更改

时间:2012-07-19 19:14:14

标签: .net winforms splitcontainer

My Winforms应用程序在数据库中保存并恢复其GUI状态。一切都运行正常,除了Split Container的SplitterDistance。

该值已正确加载并从DB设置,但当我退出应用程序而不触摸拆分器时,我希望它保存相同的值。但它保存初始值减去25像素。如果我多次打开和关闭应用程序,分割器距离每次都会减少25个像素。

它不是一个自定义控件,只是一个普通的.NET SplitContainer。只能以编程方式访问控件以加载其初始SplitterDistance并将其保存在退出时,没有别的。

我该如何解决这个问题?

更新:spl的FixedPanel属性最初设置为None。尝试将其设置为Panel1Panel2;在这两种情况下,当我保存它时,SplitterDistance 增长 50像素。

4 个答案:

答案 0 :(得分:1)

您是否在拆分容器中有用户控件,并且可能在它们全部加载时,它将与包含它的用户控件一起调整大小。

要解决此问题,请设置 FixedPanel 属性并观察它。

答案 1 :(得分:0)

download sample application

import abc
import logging


class BaseServer(abc.ABCMeta):

    def serve(self):
        pass  # serving code (should register the _callback method)

    def _callback(self, request):
        try:
            logging.info("Received request: %s", request)
            self._handle(request)
        except ParsingError as e:
            logging.error("Parsing failed:", exc_info=e.__cause__)
        except FormattingError as e:
            logging.error("Formatting failed:", exc_info=e.__cause__)
        except SendingError as e:
            logging.error("Sending failed:", exc_info=e.__cause__)
        except Exception:
            logging.exception("Processing failed:")

    @abc.abstractmethod
    def _handle(self, request):
        raise NotImplementedError

    @classmethod
    def _parse(cls, request):
        try:
            pass  # parsing code
        except Exception as e:
            raise ParsingError from e

    @classmethod
    def _format(cls, response):
        try:
            pass  # formatting code
        except Exception as e:
            raise FormattingError from e

    @classmethod
    def _send(cls, response):
        try:
            pass  # sending code
        except Exception as e:
            raise SendingError from e


class ParsingError(Exception):
    pass


class FormattingError(Exception):
    pass


class SendingError(Exception):
    pass

答案 2 :(得分:0)

我使用了以下响应(我的分离器是垂直的):

private void Form1_Load(object sender, EventArgs e) 
{
    int splitContainery = Properties.Settings.Default.SplitterDistance;
    if(splitContainery < splContainer.ClientSize.Width)
        splContainer.SplitterDistance = splContainer.ClientSize.Width - splitContainery;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    int splitContainery = splContainer.ClientSize.Width - splContainer.SplitterDistance;
    Properties.Settings.Default.SplitterDistance = splitContainery;
    Properties.Settings.Default.Save();            
}

我为splContainer.SplitterDistance创建了PropertyBinding,但没有将其绑定到属性,只是将其包含在ApplicationSettings文件中。

答案 3 :(得分:-1)

int splitContainery = Properties.Settings.Default.SplitterDistance;

如果我可以使用Properties.Settings.Default.SplitterDistance,那么我就永远不能使用 ini 文件