我如何在WinForms应用程序中创建一行? [英] How can I create a line in a WinForms Application?

查看:97
本文介绍了我如何在WinForms应用程序中创建一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在WinForms应用程序中创建一个简单的3D线,以改善我的表单布局的可视布局。
这行非常类似于关于Windows对话框中的行(可以在Windows资源管理器 - >帮助 - >关于Windows中打开)。



检查一个示例此处。最后一行(3D)是我想要的,而不是第一行。



这怎么能在C#或Visual Basic(.NET)中完成?



Thanks

解决方案

如果使用SysInternals的ZoomIt实用程序,这只是两条线。白色之上的深灰色。使用Graphics.DrawLine()绘制线条非常简单,您只需确保选择与该窗体的BackColor配合良好的深色。如果用户选择另一个主题,那并不总是灰色的。

这个示例代码是可用的:

  protected override void OnPaint(PaintEventArgs e){
Color back = this.BackColor;
Color dark = Color.FromArgb(back.R>> 1,back.G>> 1,back.B>> 1);
int y = button1.Bottom + 20;
using(var pen = new Pen(dark)){
e.Graphics.DrawLine(pen,30,y,this.ClientSize.Width - 30,y);
}
e.Graphics.DrawLine(Pens.White,30,y + 1,this.ClientSize.Width - 30,y + 1);
}

请注意,在此代码中使用button1,以确保行在正确的高度绘制,即使表格被重新缩放。选择您自己的控件作为该行的参考。


I want to create a simple 3D line in a WinForms application to improve visual arrangement of my form layout. This line is exacly like the line in About Windows dialog (can be opened in Windows Explorer -> Help -> About Windows).

An example be checked here. The last line (3D) is the one I want, not the first one.

How can this be done in C# or Visual Basic (.NET)?

Thanks

解决方案

If you use SysInternals' ZoomIt utility, you can see that this is simply two lines. A dark gray one above a white one. Drawing lines is simple enough with Graphics.DrawLine(), you just need to make sure you pick a dark color that work well with the form's BackColor. That isn't always battleship gray if the user selected another theme. Which makes the GroupBox trick fall flat.

This sample code is serviceable:

    protected override void OnPaint(PaintEventArgs e) {
        Color back = this.BackColor;
        Color dark = Color.FromArgb(back.R >> 1, back.G >> 1, back.B >> 1);
        int y = button1.Bottom + 20;
        using (var pen = new Pen(dark)) {
            e.Graphics.DrawLine(pen, 30, y, this.ClientSize.Width - 30, y);
        }
        e.Graphics.DrawLine(Pens.White, 30, y+1, this.ClientSize.Width - 30, y+1);
    }

Note the use a button1 in this code, there to make sure the line is drawn at the right height, even when the form is rescaled. Pick your own control as a reference for the line.

这篇关于我如何在WinForms应用程序中创建一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆