我只想知道在不使用GDI +的情况下在窗体中绘制线条的最佳方式,而是使用工具箱中的控件。在Windows窗体中绘制一条线的最佳方式C#
0
A
回答
3
您可以使用Visual Basic电源包线形状类 - http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.lineshape.aspx
使用Label控件
- 另一种解决方案添加一个Label控件到窗体。
- 将标签文本设置为空。
- 将BorderStyle设置为Fixed3D。
- 将AutoSize设置为false。
- 将高度设置为2(最容易通过在标签属性下的大小/高度字段中输入2来完成)。
3
可能不是最好的选择,但应该帮助
Label lbl = new Label();
lbl.Text = "_________________________________";
this.Controls.Add(lbl);
-1
你可以用我的控制:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class AmenLine : Control
{
bool SzChInternaly;
public enum EDIR : int
{
Horizontal = 0,
Vertical = 1,
Slash = 2,
BKSlash = 3
}
public enum eStyle : int
{
rect = 0,
circ = 1
}
private eStyle _DrawStyle;
public eStyle DrawStyle {
get { return _DrawStyle; }
set {
_DrawStyle = value;
BuildMe(_Direc);
}
}
private EDIR _Direc = EDIR.Horizontal;
public EDIR Direction {
get { return _Direc; }
set {
if ((value == EDIR.Horizontal && _Direc == EDIR.Vertical) | (value == EDIR.Vertical && _Direc == EDIR.Horizontal)) {
SzChInternaly = true;
this.Size = new Size(this.Height, this.Width);
}
_Direc = value;
BuildMe(value);
}
}
private void BuildMe(EDIR BodyDir)
{
try {
SzChInternaly = true;
Drawing2D.GraphicsPath gr = new Drawing2D.GraphicsPath();
switch (BodyDir) {
case EDIR.Horizontal:
this.Size = new Size(this.Width, _BorderWidth + 10);
gr.AddRectangle(new Rectangle(0, (-_BorderWidth + this.Height)/2, this.Width, _BorderWidth));
break;
case EDIR.Vertical:
this.Size = new Size(_BorderWidth + 10, this.Height);
gr.AddRectangle(new Rectangle((-_BorderWidth + this.Width)/2, 0, _BorderWidth, this.Height));
break;
case EDIR.Slash:
try {
// CType(_BorderWidth * Height/Width, Integer)
for (i = 0; i <= Convert.ToInt32(Math.Pow(Math.Pow(Width, 2) + Math.Pow(Height, 2), 0.5)); i += _BorderWidth) {
switch (_DrawStyle) {
case eStyle.circ:
gr.AddPie(i, Convert.ToInt32(Height * i/Width), _BorderWidth, _BorderWidth, 0, 360);
break;
case eStyle.rect:
gr.AddRectangle(new Rectangle(i, Convert.ToInt32(Height * i/Width), _BorderWidth, _BorderWidth));
break;
}
}
} catch {
}
break;
case EDIR.BKSlash:
try {
// CType(_BorderWidth * Height/Width, Integer)
for (i = 0; i <= Convert.ToInt32(Math.Pow(Math.Pow(this.Height, 2) + Math.Pow(this.Width, 2), 0.5)); i += _BorderWidth) {
switch (_DrawStyle) {
case eStyle.circ:
gr.AddPie(Width - 1 - i, Convert.ToInt32(Height * i/Width), _BorderWidth, _BorderWidth, 0, 360);
break;
case eStyle.rect:
gr.AddRectangle(new Rectangle(Width - 1 - i, Convert.ToInt32(Height * i/Width), _BorderWidth, _BorderWidth));
break;
}
}
} catch {
}
break;
}
this.Region = new Region(gr);
SzChInternaly = false;
} catch {
}
}
private int _BorderWidth = 1;
public int BorderWidth {
get { return _BorderWidth; }
set {
_BorderWidth = value;
BuildMe(_Direc);
}
}
public AmenLine()
{
this.BackColor = Color.Black;
BuildMe(_Direc);
}
protected override void OnSizeChanged(System.EventArgs e)
{
base.OnSizeChanged(e);
if (SzChInternaly == false)
BuildMe(_Direc);
}
}
-1
您可以通过画线运行代码如下:
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0));
e.Graphics.DrawLine(pen, 20, 10, 300, 100);
0
来源:http://www.csharp-examples.net/separator-line/
// separator bevel line
Label labelSeperator = new Label();
labelSeperator.AutoSize = false;
labelSeperator.Height = 2;
labelSeperator.BorderStyle = BorderStyle.Fixed3D;
this.Controls.Add(labelSeperator);
相关问题
- 1. 绘制线条的最佳方式java
- 2. 绘制移动线条/曲线的最佳方式是什么?
- 3. C#如何在Windows窗体上的两个对象之间绘制一条线?
- 4. 是pictureBox绘制线条的最佳方式
- 5. 在窗体上绘制线条网格
- 6. 用Windows窗体在Visual Studio C++中绘制线程图
- 7. 无法在Windows窗体图表控件上绘制线条
- 8. 在Windows窗体中绘制立方体的最简单方法是什么?
- 9. 以编程方式操作手绘线条的最佳方法
- 10. Windows窗体绘制效率低下 - C#
- 11. 以c#windows窗体形式异步下载文件的最佳方式vs 2005
- 12. 在Mathematica中绘制最佳曲线
- 13. 如何在窗体上绘制一条线?
- 14. 在窗口内绘制Windows窗体
- 15. C++/Win32在Windows 2000 +上启动线程的最佳方式
- 16. 在Windows窗体中绘制30fps图表
- 17. 使Windows窗体可扩展的最佳方式?
- 18. 什么是保存/加载Windows窗体的最佳方式ToolStripMenuItem
- 19. 在Windows窗体中暂停控件事件的最佳方法?
- 20. 在c#图上绘制一条线
- 21. 在LaTeX中绘制条形图的最佳方法是什么?
- 22. 在windows窗体中的图像上绘制覆盖图的最快方法
- 23. 编写GUI的最佳方式(C++/Windows)
- 24. 在Windows窗体中绘图
- 25. 控制c中并发线程数的最佳方式#
- 26. 什么是在Windows窗体中进行验证的最佳方式
- 27. 用c绘制线条/正方形#
- 28. C#从窗体中控制一个窗体中的菜单条形式
- 29. 在Python中绘制基于web的图形的最佳方式
- 30. 需要透明覆盖窗口在窗口绘制视频顶部绘制线条? :: MFC,C++,windows ::
您可以使用工具箱中的Visual Basic的PowerPack下有线状。 –
什么样的线?你可以绘制一个带有黑色边框的1像素宽面板(虽然它的绘制方法会使用gdi +我相信)或者为边框样式调用gdi32.dll(不加) – Sayse