c# 鼠标移动一条画好的线,鼠标到了哪里线就跟着到了哪里?
解决方案 »
- 有什么控件能够直接浏览 doc jpg dwg等格式文件
- 数据库的选择
- 关于网络打印机的编程
- 小妹求助,如何用程序启动另一个打开的VS2005工程
- 帮忙调试下一段代码
- c# gdi+画图,如何统计图上的直线数目,即如何运用arraylist统计直线的数目?
- Regex rep = new Regex(" (src|href|background|value)=('|\"|)([^('|\"|)http://].*?)('|\"| |>)"); 正则怎么理解啊
- 菜鸟刚学c#,想实现这个样的功能,当我选中datagrid的一条记录时,把这条记录的相关信息赋到几个textbox里,比如textbox1里得到的值是姓
- 如何将一任意文件的1024字节后的内容放到一个数组中?
- "找不到可安装的 ISAM"是怎么回事?
- Datalist控件多行多列显示时,为什么总是只显示一行多列?
- 图片类型转换
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;namespace MPicture
{
public partial class Form1 : Form
{
private Graphics g;
private string[] strTitle ={ "(00-07)点", "(08-15)点", "(16-23)点" };
private string[,] strTitle1=new string[3,8]; public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
#region 标题
int k = -1;//临时变量存储1到23的值
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 8; j++)
{
k++;
strTitle1[i,j] = Convert.ToString(k);
}
}
#endregion 标题
}
#region pictureBox1的相关函数
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
#region 基本参数
Graphics g = e.Graphics;
Pen GreenPen = new Pen(Color.Green, 2);
Brush brush = GreenPen.Brush;
GreenPen.DashStyle = DashStyle.Solid; //定义画线类型为虚线
#endregion 基本参数 #region 画横线和竖线
GetHLien(g,pictureBox1,pictureBox1.Height,70,GreenPen,brush);
GetSLine(g, pictureBox1, pictureBox1.Width, GreenPen, brush, strTitle1,strTitle);
#endregion 画横线和竖线
base.OnPaint(e);
}
/// <summary>
/// 画横线
/// </summary>
/// <param name="g"></param>
/// <param name="p1"></param>
/// <param name="height"></param>
/// <param name="step"></param>
/// <param name="Hpen"></param>
/// <param name="Hbrush"></param>
private void GetHLien(Graphics g,PictureBox p1, int height, int step,Pen Hpen,Brush Hbrush)
{
int i=0;
if (g != null)
{
for (i = 0; i < height; i += step)
{
g.DrawLine(Hpen, 0, 0 + i, pictureBox1.Right, 0 + i);
}
}
}
/// <summary>
/// 画竖线
/// </summary>
/// <param name="g"></param>
/// <param name="p1"></param>
/// <param name="width">画布的整体宽度</param>
/// <param name="Spen"></param>
/// <param name="Sbrush"></param>
/// <param name="strTitle1">第一列的标题</param>
/// <param name="strTitle">其他列的标题</param>
private void GetSLine(Graphics g,PictureBox p1,int width,Pen Spen,Brush Sbrush,string[,]strTitle1 ,string[] strTitle)
{
int i,j,m,n;
Rectangle rect = new Rectangle();
rect.X = p1.Left;
rect.Y = p1.Top;
rect.Width = 0;
rect.Height = 0; StringFormat f1 = new StringFormat(StringFormatFlags.LineLimit);
f1.Alignment = StringAlignment.Center;
f1.LineAlignment = StringAlignment.Center; int colWidth = 0;//每列的宽度
int firstCol = 0;//第一列的宽度 colWidth = (int)((p1.Width-102) / 8);//除第一列的每列的宽度
firstCol = 102;
#region 第一列
g.DrawLine(Spen, 0, 0, 0, p1.Bottom);//第一列
g.DrawLine(Spen, firstCol, 0, firstCol, p1.Bottom);//第二列
for (i = 0; i < strTitle .Length; i++)
{
rect.Width = firstCol;
rect.Height = p1.Height / strTitle.Length;
g.DrawRectangle(Spen, rect);
g.DrawString(strTitle[i], new Font("黑体", 12), Sbrush, rect, f1);
rect.Y += rect.Height;
}
#endregion 第一列 #region 其他列
f1.Alignment = StringAlignment.Center;
f1.LineAlignment = StringAlignment.Far;
for (i = firstCol + colWidth; i <= width; i += colWidth)
{
g.DrawLine(Spen, 0 + i, 0, 0 + i, pictureBox1.Bottom);
}
for (i = firstCol + colWidth,m=0; i <= width; i += colWidth,m++)
{
rect.X =i-colWidth;
rect.Width=colWidth;
rect.Y = 0;
for (j = rect.Height,n=0; j <= p1.Height; j += rect.Height,n++)
{
g.DrawRectangle(Spen, rect);
g.DrawString(strTitle1[n,m], new Font("黑体", 12), Sbrush, rect, f1);
rect.Y += rect.Height;
}
}
#endregion 其他列
}
#endregion pictureBox1的相关函数 private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
g = this.pictureBox1.CreateGraphics();
g.DrawLine(new Pen(Brushes.Red, 1), e.X, 0, e.X, 622);
}
}
}