AutoSize和高度属性

时间:2017-12-15 16:36:52

标签: c# winforms

我正在尝试使用循环自动填充一些标签。

<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/> <!-- must be first; see SD5930 -->
    <title>Test URL login</title>
    <!--meta name="apple-mobile-web-app-capable" content="yes" /-->
    <link type="text/css" rel="StyleSheet" href="/nl/logon.css"></link>
  </head>
  <body onLoad="setFocus();">
    <div id="htmlContent">
      <div id="container">
        <div id="content">
          <div class="login_frame">
            <div class="header_login">
              <img src="/nl/img/logo.png" alt="Test URL" />
            </div>
            <div id="form-main">
              <!--[if lte IE 7]>
              <div class="warning"><b>Warning</b>: your browser isn't supported by Test URL. <br/>To be able to use Test URL to its full potential, you need to update your browser.</div>
              <![endif]-->
              <form method="POST" autocorrect="off" autocapitalize="off" name="loginForm" action="/nl/jsp/logon.jsp">
                <input type="hidden" name="action" value="submit" />

                <input type="hidden" name="target" value="/acx/databaseUsage.jssp?object=all">

                <p class="input first">
                  <label for="login">Login</label>
                  <span>
                    <input id="login" name="login" tabindex="1" type="text" value="" />
                  </span>
                </p>
                <p class="input">
                  <label for="password">Password</label>
                  <span>
                    <input id="password" name="password" tabindex="2" type="password" autocomplete="off" />
                  </span>
                  <br />
                </p>
                <p class="memorize submit last">

                    <input id="rememberMe" name="rememberMe" class="checkbox" tabindex="3" type="checkbox" />
                    <label class="checkbox" for="rememberMe">Keep me logged in</label>

                  <button id="validate" type="submit">Log in</button>
                </p>
              </form>
            </div>

          </div>
        </div>
      </div>


      <div id="footer" class="dashboardFooter">
        <div id="footerContent" class="nlui-pageWidth">
          <p>
          &copy; Test URL 2017
          </p>
        </div>
      </div>

    </div>
    <script type="text/javascript">
      function setFocus() {
        document.loginForm.login.focus();
      }
    </script>
  </body>
</html>

无论是否设置自动调整大小,高度始终返回23.因此,如果我将自动调整大小设置为假,我会看到边框太大,但很好地打包在一起。如果我将它设置为true,我会看到完美的边框,除非它们之间存在很大差距。

似乎边框与控件的高度不同,我不知道如何调整它以使它们相同。

1 个答案:

答案 0 :(得分:2)

在将标签添加到容器之前,AutoSize不会发生。因此,请尝试切换以下两行代码:

labelLocation = new Point(labelLocation.X, workingLabel.Location.Y + workingLabel.Height);
box.Controls.Add(workingLabel);

box.Controls.Add(workingLabel);
labelLocation = new Point(labelLocation.X, workingLabel.Location.Y + workingLabel.Height);