显示和隐藏 winforms 的部分内容(扩展?)C# .NET

发布于 2024-10-18 07:00:42 字数 167 浏览 1 评论 0原文

我有关于表单和控件的问题。我想添加一种功能,使表单的一部分仅在单击某些内容时显示。例如,我有 form1,在表单上我有一个按钮,当单击该按钮时,表单会增长或扩展(滑出?)以显示单击按钮之前不存在的其他控件。我不知道这叫什么,所以我不知道要寻找什么,但我已经看到它在许多其他应用程序中使用。任何有关这方面的信息将不胜感激。

I have a question about forms and controls. I want to add the ability to sort of make a part of my form only show when something is clicked. For example I have form1 and on the form i have a button and when that button is clicked the form grows or extends (slides out?) to show other controls that werent there before the button was clicked. I have no idea what this is called so I don't know what to look for but Ive seen it used in many other applications. Any information on this would be greatly appreciated.

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

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

发布评论

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

评论(2

日久见人心 2024-10-25 07:00:42

您可能必须滚动自己的动画,在计时器上增加表单(或面板或其他)的尺寸,从而暴露以前隐藏的控件。

        Timer T = new Timer();
        T.Interval = 10;
        T.Tick += (s, e) =>
        {
            myForm.Size = new System.Drawing.Size(myForm.Width + 10, myForm.Height);
            if (myForm.Size.Width >= FormWidthThreashold)
                T.Stop();
        };
        T.Start();

冒着陈述显而易见的风险,我不认为有任何方法可以切换 WPF?这个东西是内置的,对于 WPF 来说非常容易。如果没有,类似这样的事情应该可以帮助你开始。

You'd probably have to roll your own animation, increasing the size dimensions of your form (or panel, or whatever) on a timer, thereby exposing the previously hidden controls.

        Timer T = new Timer();
        T.Interval = 10;
        T.Tick += (s, e) =>
        {
            myForm.Size = new System.Drawing.Size(myForm.Width + 10, myForm.Height);
            if (myForm.Size.Width >= FormWidthThreashold)
                T.Stop();
        };
        T.Start();

At the risk of stating the obvious, I don't suppose there's any way to switch the WPF? This stuff is built in, and quite easy for WPF. If not though, something like this should get you started.

与往事干杯 2024-10-25 07:00:42

我以前做过这个。首先将表单组织成逻辑部分。不要将所有控件都留在窗体上,而是将它们放在面板内。在设计时,您需要让面板“完全展开”,但在运行时,您可以通过代码操纵面板的左侧、顶部、宽度、高度,甚至可能是对齐和锚点属性。您可以按照@Adam Rackis 的建议使用计时器。或者您可以更改增量值来改变动画的速度。动画本身只是一个以 x = x1 开始并以 x = x2 结束的循环,其中循环内的 x = x +increment_value。当“x”的值发生变化时,组件将自动重绘。为了获得更平滑的效果,您可能需要在每次迭代时重新绘制控件(或整个面板)。如果它运行得太快,您可以插入延迟或尝试使循环依赖于计时器。我在处理这类事情时遇到过定时器问题,但不可否认的是,我当时没有使用 C#.NET(我是在 Delphi 中完成的)。需要对细节进行大量调整才能使其正常工作,因此请耐心等待,这不是 Flash!祝你好运。

I've done this before. Start by organising your form into logical sections. Don't leave all your controls on the form, place them inside panels. At Design-time you'll need to have the panels "fully expanded", but then at runtime you manipulate the panels' left, top, width, height, and maybe even the alignment and anchors properties, through code. You could use a timer as suggested by @Adam Rackis.. or you could change the increment value to alter the speed of the animation. The animation itself is just a loop that starts with x = x1 and ends with x = x2, where x = x + increment_value inside the loop. As the value of "x" changes, the component will be automatically redrawn. To get a smoother effect you might need to repaint the control (or the entire panel) on each iteration. If it runs too fast, you can either insert a delay or try to make the loop rely on a timer. I've had problems with timers for this kind of stuff, but admittedly I wasn't using C#.NET at the time (I did it in Delphi). It takes a lot of fiddling with the fine details to get this working nicely, so be patient, it's not Flash! Good luck.

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