C# .net 框架 - 边框仅位于表单的一侧

发布于 2024-08-05 06:02:08 字数 405 浏览 1 评论 0 原文

我是一个没有经验的程序员,对 Windows 编程完全陌生。

我正在编写一个我一直想要的小程序。它是使用 C# 和 .net 框架编写的。至少我想我就是这么做的。所有关于框架和 .nets 、 windows forms 和 win32 api 的讨论都让我非常困惑..:(

无论如何,我有简单的 Form 对象。

 Form f = new Form() ;
 f.Text = "" ;   
 f.ControlBox =false ;

现在如何删除表单上除一侧之外的所有边框?如,侧面边框应该消失,但顶部边框应该保留

FormBorderStyle 对此没有任何内容

另外,您如何自己解决此类问题,而不询问其他人的代码? 我用谷歌搜索过,但什么也没找到。

I am an inexperienced programmer , completely new to programming for windows .

I am writing a little program that I always wanted . Its being written using C# using .net framework. atleast thats what I think I am doing. All the talk about framework and .nets , windows forms , and win32 api has all got me really confused.. :(

anyways I have simple Form object.

 Form f = new Form() ;
 f.Text = "" ;   
 f.ControlBox =false ;

Now How to remove the all the borders on the form except one sides? As in, the side borders should go , but the top border should stay

FormBorderStyle doesn't have anything for this

Also how do you people solve such problems yourself , without asking ? look at others code ? read a a book ? any particular website ?
I have googled , but it didn't turn up nothing.

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

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

发布评论

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

评论(3

つ低調成傷 2024-08-12 06:02:08

Gidday,

不幸的是,这是不可能的 - 不过,您可以删除整个边框,然后在表单上绘制自己的边框,并使用 OnMouseDown、OnMouseUp 和 OnMouseMove 进行自己的拖动...

要自己解决这样的问题,我会看看以各种不同的方式口头表达问题(例如“无边界形式”、“winform 上的自定义边界”等),并花一些时间谷歌搜索它。正如我的老板明智地说的那样,生产力并不总是与您削减了多少代码有关,还与您可以学到什么有关。

编辑:正如流行的说法所说,“谷歌知道一切” - 很可能,如果你花一点时间谷歌搜索,但仍然找不到任何东西,那么它可能还没有得到解决,或者非常罕见。另一种方法是购买一些好书,例如 Windows 窗体编程(甚至只是 Windows 编程 - 了解 Windows 的底层机制非常有用,诸如此类的东西可以帮助您成为一名出色的开发人员。优秀的程序员擅长编码,但优秀的开发人员擅长实际构建有用的软件:)。

Gidday,

This is impossible, unfortunately - you can remove the whole border, though, and then draw your own on the form and use OnMouseDown, OnMouseUp and OnMouseMove to do your own dragging...

To solve such a problem myself, I would look at various different ways of verbally representing the problem (eg. "borderless form", "custom borders on winform", etc) and spend a bit of time Googling for it. As my boss wisely says, productivity isn't always about how much code you cut, it's also about what you can learn.

EDIT: As the popular expression goes, "Google knows all" - chances are that, if you spend a bit of time googling and you still can't find anything, then it probably hasn't been solved, or it's very very rare. Another way would be to invest in a few good books, e.g. Windows Forms programming (or even just Windows programming - it's incredibly useful to know about the underlying mechanics of Windows, and things like that are what help turn you into a great developer. A great programmer is good at coding, but a great developer is good at actually building useful software. :)

ぃ双果 2024-08-12 06:02:08

我假设您尝试过 FormBorderStyle.FixedSingle?这将显示一个仅在顶部有边框的表单。
无论如何,如果不是这种情况,您可以设置表单区域。

就像...

public static void HideBorders(Form form)
{
    Rectangle newRegion = form.Bounds;
    Rectangle formArea = form.Bounds;
    Rectangle clientArea = form.RectangleToScreen(form.ClientRectangle);

    formArea.Offset(form.Location);
    newRegion.Offset(clientArea.X - formArea.X, 0);
    newRegion.Width = clientArea.Width;
    newRegion.Height = (clientArea.Y - formArea.Y) + clientArea.Height;

    form.Region = new Region(newRegion);
}

至于你怎么知道该怎么做?您提到的所有内容、帮助文件、网络论坛、书籍。最重要的是练习,练习,再练习。你做的事情越多,你就应该变得越好。

I assume you've tried FormBorderStyle.FixedSingle? This would display a form with a border at the top only.
Anyway, if that isn't the case you can set the forms Region.

Something like...

public static void HideBorders(Form form)
{
    Rectangle newRegion = form.Bounds;
    Rectangle formArea = form.Bounds;
    Rectangle clientArea = form.RectangleToScreen(form.ClientRectangle);

    formArea.Offset(form.Location);
    newRegion.Offset(clientArea.X - formArea.X, 0);
    newRegion.Width = clientArea.Width;
    newRegion.Height = (clientArea.Y - formArea.Y) + clientArea.Height;

    form.Region = new Region(newRegion);
}

As for how do you know what to do? All of the things you mentioned, help files, web forums, books. The main thing is practice, practice, practice. The more you do something the better you should become.

沉鱼一梦 2024-08-12 06:02:08

我认为实际上不可能完全按照您所描述的方式进行操作,因为 .NET Framework 只是将窗体边框和标题栏的绘制委托给 Windows 本身,而 Windows 本身没有任何您所描述的选项。

相反,我要做的是使用 FormBorderStyle.None,然后手动绘制您想要的任何窗口装饰(标题栏、边框)。

在 Google 中搜索“无边框形式 C#”,这些网站将出现在排名前三的搜索结果中:

I don't think it's actually possible to do exactly what you describe, since the .NET Framework is just going to delegate the drawing of your Form's border and title bar to Windows itself, which doesn't have any option for what you describe AFAIK.

Instead, what I would do is use FormBorderStyle.None and then draw any window decorations (title bar, borders) you want manually.

A Google search for "borderless form C#" turns up these sites as the top three hits:

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