控件布局模板

发布于 2024-09-27 04:47:41 字数 308 浏览 1 评论 0原文

我需要一种在页面中布局控件的方法。 让我举例问你。
我有四个不同的操作按钮(编辑、删除等),它们在任何页面上执行相同的操作,但有时我希望它们水平排列,有时垂直排列,具体取决于哪个页面显示它们。
因此,我考虑将所有四个按钮放置在用户控件中,并使用某种模板控件来管理它们的布局。

是否存在这样一个像ListView的模板管理一样灵活的控件?
当然,一个懒惰的解决方案是在一个面板中水平放置四个按钮,在另一个面板中垂直放置另外四个按钮,然后显示/隐藏所需的面板,但我不想有两个按钮实例;我只想要每个按钮的一个实例,但布局不同。

请随意为此添加更多标签。

I need a way to layout controls in a page.
Let me ask you by example.
I have four different action buttons (Edit, Delete, etc..) that do the same actions on any page, but sometimes I want them laid out horizontally and some other times vertically, depending on which page is displaying them.
So I thought of placing all four buttons in a user control and manage their layout using some sort of template control.

Does such a control exist that is as flexible as ListView's template management?
Of course a lazy solution is to place four buttons horizontally in a panel, and another four buttons vertically in another panel, and show/hide the panel that's requested, but I don't want to have two instances of the buttons; I just want one instance of each button, but in different layouts.

Feel free to add more tags to this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野心澎湃 2024-10-04 04:47:41

这样的事情可以用CSS来实现。我在 CSS 方面很糟糕,但我相信这可行:

HTML

<div class="horizontal">
    <input type="button" value="1" />
    <input type="button" value="2" />
    <input type="button" value="3" />
    <input type="button" value="4" />
</div>

您只需在 div 元素中设置所需的两个 CSS 类(您可以使用 UserControl 包装按钮并将 div 的类映射到 UserControl 的属性)

  <head>
    <style type="text/css">
        .horizontal input 
        {
            margin:0px 2px 0px 2px;
        }

        .vertical input
        {
            display:block;
            margin:2px 0px 2px 0px;
        }
    </style>
  </head>

模板化控件对于如此简单来说太强大了特别是当您不需要更改模板内容时。

Such thing can be achieved with CSS. I'm bad in CSS but I believe this works:

HTML

<div class="horizontal">
    <input type="button" value="1" />
    <input type="button" value="2" />
    <input type="button" value="3" />
    <input type="button" value="4" />
</div>

Two CSS classes you simply set which you need in the div element (you can wrap your buttons with UserControl and map div's class to UserControl's property)

  <head>
    <style type="text/css">
        .horizontal input 
        {
            margin:0px 2px 0px 2px;
        }

        .vertical input
        {
            display:block;
            margin:2px 0px 2px 0px;
        }
    </style>
  </head>

Templated control is to strong for such easy task especially when you do not need to change template content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文