C#编程学习(04):基本操作学习总结

一、对话框窗体的设计

(1)修改exe图标:项目-->右键-->属性-->应用程序-->图标和清单-->图标,选择要添加的图标

(2)修改对话框图标: 点击对话框 --> 属性 --> ICON

(3)固定对话框大小:点击对话框 --> 属性 -->FormBorderStyle: FixedDialog

(4)最大化、最小化按钮不可用:MinimizeBox: False; MaximizeBox: False

(5)修改标题:Text

二: 文件文本的处理

(1)对于包含不确定数目空格的文本文件读入

首先添加引用:using System.Text.RegularExpressions;

忽略空格进行字符串分割:string[] substrtmp = Regex.Split(nextLine, "\\s+", RegexOptions.IgnoreCase);

(2)弹出文件选择对话框

OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
inputPath = ofd.FileName;

(3)打开文件度数据

System.IO.StreamReader inputFile = System.IO.File.OpenText(inputPath);

string firstLine = inputFile.ReadLine();

inputFile.Close();
//释放对象
inputFile.Dispose();

(4)遍历文件

 string nextLine;
 while ((nextLine = inputFile.ReadLine()) != null)
  {
      //对数据及对文件的操作
}

(5)写文件

System.IO.StreamWriter outputFile = System.IO.File.OpenText(inputPath);

三、绘图API的使用

(1)根据宽度和高度创建位图

System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);

(2)创建Graphics类对象
  Graphics g = Graphics.FromImage(image);

(3)清空图片背景色
            g.Clear(Color.White);

(4)指定字体

Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);

(5)绘制矩形

Point pt_leftUp = new Point(30, 30);
 g.DrawRectangle(画笔对象, 左上点X,左上点Y,宽度,高度);

示例:

g.DrawRectangle(new Pen(Color.Black), pt_leftUp.X, pt_leftUp.Y, image.Width - pt_leftUp.X * 2, image.Height - pt_leftUp.Y * 2);

(6) 绘制椭圆

DrawEllipse(画笔,左上点x,左上点y,宽度,高度);

(7)绘制字符串

DrawString(要标注的字符串,字体,画刷,x坐标值,y坐标值);
 (8)填充椭圆      
 g.FillEllipse(new SolidBrush(item.Color), stlPoint.X - stlSize / 2, stlPoint.Y - stlSize / 2, stlSize, stlSize);

猜你喜欢

转载自blog.csdn.net/m1m2m3mmm/article/details/84571979
今日推荐