更改表单的前景色

发布于 2024-08-19 01:42:24 字数 67 浏览 4 评论 0原文

我如何更改表单的前景色,已将前景色设置为红色,但表单仍以白色文本显示。我该如何改变这个。
我指的是标题栏文本颜色

How do i change the ForColor of the form, have set the ForeColor to RED but the form still displays in Whte Text. How do i change this.
Am refering to Title Bar Text Color

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

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

发布评论

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

评论(3

时光倒影 2024-08-26 01:42:24

标题栏是表单的“非客户端”区域。表单的非客户区由 Windows API 管理,而不是由 .NET 管理。它不能通过在表单上设置任何属性来更改。要更改标题栏文本的颜色,您需要进行自定义绘画。在 Google 中搜索以下术语:非客户区绘画 winform。您需要直接调用 Win32 API 才能使其工作。您可以从这里得到一些想法: 链接http://customerborderform。 codeplex.com/wikipage?title=Painting%20NonClient%20Area&referringTitle=Home

在过去(即没有 .NET 的时候),这样做更容易,因为我们直接使用 Win32 API。我这么做是为了好玩。而且,从那以后我了解到这些东西对于学习来说是可以的; IMO 我强烈建议您不要将其放入“真实”应用程序中来“滥用”它。 Windows 具有一定的外观和感觉,并且该外观和感觉应该由用户而不是开发人员控制。

The title bar is a "non client" area of the form. Non-client area of the form is managed by windows API, and not by .NET. It cannot be changed by setting any property on a form. To change the color of the Title bar text, you would need to do custom painting. Search Google for terms like: non-client area painting winforms. You would need to make calls to the Win32 API directly for this to work. You can get some ideas from here: Link and http://customerborderform.codeplex.com/wikipage?title=Painting%20NonClient%20Area&referringTitle=Home

It was easier to do back in the day (that is, when there was no .NET), since we directly used the Win32 API. I did it, for fun. And, I have since learned that such things are ok for learning; IMO I strongly recommend that you don't "misuse" this by putting it in a "real" application. Windows has a certain look and feel, and that look and feel should be under the user's control, not the developer's.

丿*梦醉红颜 2024-08-26 01:42:24

我不确定你想做什么。
ForeColor 更改窗体上子控件的颜色。
以下是使用前景色和在 Windows 窗体上书写的示例。
请注意,通过 Graphics 对象直接在 Form 上写入时,不使用 Form ForeColor 属性...
在表单上放置一个按钮并将代码放入其事件处理程序中......

private void button1_Click(object sender, EventArgs e)
    {
        this.ForeColor = System.Drawing.Color.Red;
        using (Graphics g = this.CreateGraphics())
        {
            Brush b = new SolidBrush(System.Drawing.Color.Blue);
            g.DrawString("SAMPLE TEXT", SystemFonts.CaptionFont, b, new PointF(50, 50));
            b.Dispose();
        }
    }

I'm not sure what you are trying to do.
ForeColor changes the color for Child Controls on the Form.
Here is a sample of use for ForeColor and for writing on a windows Form.
Note that the Form ForeColor property is not used when writing directly on the Form through a Graphics object...
Put a button on your form and put the code in its event handler ...

private void button1_Click(object sender, EventArgs e)
    {
        this.ForeColor = System.Drawing.Color.Red;
        using (Graphics g = this.CreateGraphics())
        {
            Brush b = new SolidBrush(System.Drawing.Color.Blue);
            g.DrawString("SAMPLE TEXT", SystemFonts.CaptionFont, b, new PointF(50, 50));
            b.Dispose();
        }
    }
囍笑 2024-08-26 01:42:24

您好,如果您想更改表单控件的文本,则必须在所有子控件、标签、复选框、文本框等上单独设置 ForeColor 属性。窗体前景色只会影响在更改窗体前景色后创建的控件。

Hi if you want to change the text of forms controls, you have to set the ForeColor property on all child controls, labels, checkboxes, textboxes, etc. individual. The forms ForeColor will only affect controls that are created after the forms forecolor was changed.

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