Windows窗体中的简单行 [英] A simple line in windows form
本文介绍了Windows窗体中的简单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿
如何在Windows窗体中绘制一条简单的线?这张图片中像这样的两行:
http://www.windows7howto.net/wp-content/uploads/2010/07/Windows-7-Keyboard-Shortcuts.png
Hey
How I can draw a simple line in windows form? Something like this 2 lines in this image:
http://www.windows7howto.net/wp-content/uploads/2010/07/Windows-7-Keyboard-Shortcuts.png
推荐答案
HandleControl.Paint
事件(用于控件或表单)或覆盖Control.OnPaint
.在这两种情况下,都使用从偶数参数获取的System.Drawing.Graphics
实例.使用此实例,使用System.Drawing.Graphics.Draw...
方法呈现所需的任何内容.
经OP澄清后:
我的方法将为此工作.您可以使用自定义Control
并覆盖OnPaint
,或更简单地,仅使用Panel
和Paint
事件.更改组合键时,请不要忘记:您需要致电Control.Invalidate
.而已.会成功的.
替代建议:可能您的图形元素太简单了.尝试在Unicode中找到一些好的字符(使用标准的字符映射"应用程序以查看可用的字符),并仅使用只读的TextBox
和其中的文本.对于垂直线,可以使用代码点"|":0x007C :-)或"∣" 0x2223(数学运算-除法"甚至是│" 0x2502或┃" 0x2503(箱形图,轻垂直/重垂直).
为什么使事情变得比其复杂?
—SA
HandleControl.Paint
event (for a control or a form) or overrideControl.OnPaint
. In both cases, useSystem.Drawing.Graphics
instance obtained from even argument. Using this instance, useSystem.Drawing.Graphics.Draw...
methods to render whatever you want.
After clarification by OP:
My method will work for this. You can use customControl
and overrideOnPaint
or, more simply, use justPanel
andPaint
event. When you change the key combination, don''t forget: you need to callControl.Invalidate
. That''s it. It will do the trick.
Alternative suggestion: may be you graphical element is too simple. Try to find some good character in Unicode (use standard "Character Map" application to see what''s available) and use just a read-onlyTextBox
and just text in it. For a vertical line, you can use code point ''|'': 0x007C :-) or ''∣'' 0x2223 (Mathematical Operations — "Divides" or even ''│'' 0x2502 or ''┃'' 0x2503 (Box Drawing, Light Vertical / Heavy Vertical).
Why making things more complex than they can be?
—SA
您还可以考虑使用各种形状控件:
.NET的形状控制 [高级形状控制 [ .NET的Sprite编辑器 [ FormSprite:我爱你杰西卡! [
You could also consider the various shape controls available:
Shape Control for .NET[^]
Advanced Shape Control[^]
Or if you want to do something really fancy - take a look at:
Sprite Editor for .NET[^].
You can overlay your forms with sprites as is shown in an earlier article:
FormSprite: I Love You Jessica![^]
Regards
Espen Harlinn
这篇关于Windows窗体中的简单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文