文本输出中的练习

SystemInformation类属性中包含了许多系统信息.

using System;
using   System.Drawing ;
using  System.Windows.Forms ;
namespace WindowsProgram
{  public class SysInfoString
 {
  public SysInfoString()
  {
  }
  public  static string []  lables
  {  get
   {  return new  string[]
    {"ArrangeStartingPosition",  "ArrangeStartingPosition",    "BootMode",
     "Border3DSize", "BorderSize",
     "CaptionButtonSize",
     "CaptionHeight",
     "ComputerName",
     "CursorSize",
     "DbcsEnabled",
     "DebugOS",
     "DoubleClickSize",
     "DoubleClickTime",
     "DragFullWindows",
     "DragSize",
     "FixedFrameBorderSize",
     "FrameBorderSize",
     "HighContrast",
     "HorizontalScrollBarArrowWidth",
     "HorizontalScrollBarHeight",
     "HorizontalScrollBarThumbWidth",
     "IconSize",
     "IconSpacingSize",
     "KanjiWindowHeight",
     "MaxWindowTrackSize",
     "MenuButtonSize",
     "MenuCheckSize",
     "MenuHeight",
     "MidEastEnabled",
     "MinimumWindowSize"      }; }  }
  public static  float MaxLableWidth(Graphics grfx,Font font)
  {
    return MaxWidth(lables,grfx,font);
  }
  public static int Count
  {get
   {return lables.Length; }
  }
  static float MaxWidth(string[]  astr,Graphics grfx,Font  font)
  {float fMax=0;
   foreach(string  str in  astr)
     fMax=Math.Max(fMax,grfx.MeasureString(str,font).Width);
   return  fMax;
  }
  public static string[] values
  {
   get
   {
    return new  string[]
    {  SystemInformation.ArrangeStartingPosition.ToString(),
       SystemInformation.ArrangeStartingPosition.ToString(),
     SystemInformation.BootMode.ToString(),
     SystemInformation.Border3DSize.ToString(),
     SystemInformation.BorderSize.ToString(),
     SystemInformation.CaptionButtonSize.ToString(),
     SystemInformation.CaptionHeight.ToString(),
     SystemInformation.ComputerName.ToString(),
     SystemInformation.CursorSize.ToString(),
     SystemInformation.DbcsEnabled.ToString(),
     SystemInformation.DebugOS.ToString(),
     SystemInformation.DoubleClickSize.ToString(),
     SystemInformation.DoubleClickTime.ToString(),
     SystemInformation.DragFullWindows.ToString(),
     SystemInformation.DragSize.ToString(),
     SystemInformation.FixedFrameBorderSize.ToString(),
     SystemInformation.FrameBorderSize.ToString(),
     SystemInformation.HighContrast.ToString(),
     SystemInformation.HorizontalScrollBarArrowWidth.ToString(),
     SystemInformation.HorizontalScrollBarHeight.ToString(),
     SystemInformation.HorizontalScrollBarThumbWidth.ToString(),
     SystemInformation.IconSize.ToString(),
     SystemInformation.IconSpacingSize.ToString(),
     SystemInformation.KanjiWindowHeight.ToString(),
     SystemInformation.MaxWindowTrackSize.ToString(),
     SystemInformation.MenuButtonSize.ToString(),
     SystemInformation.MenuCheckSize.ToString(),
     SystemInformation.MenuHeight.ToString(),
     SystemInformation.MidEastEnabled.ToString(),
     SystemInformation.MinimumWindowSize.ToString()     
    };  }  } }}

using System;
using   System.Drawing ;
using  System.Windows.Forms ;
namespace WindowsProgram
{
 class SystemInforList:Form
 {
     readonly  float  cxCol;
     readonly  int  cySpace;
  [STAThread]
  static void Main(string[] args)
  {
   Application.Run(new SystemInforList());
  }
  public  SystemInforList()
  {  Text="System  Information  List";
           BackColor=SystemColors.Window ;
     ForeColor=SystemColors.WindowText;
     Graphics  grfx=CreateGraphics();
     SizeF  sizef=grfx.MeasureString(" ",Font);
     cxCol=sizef.Width +SysInfoString.MaxLableWidth(grfx,Font);
     grfx.Dispose();
     cySpace=Font.Height ;//每行间隔象素
     
  }
  protected override void OnPaint(PaintEventArgs e)
  {
   Graphics grs=e.Graphics ;
   Brush brush=new SolidBrush(ForeColor);
   int iCount=SysInfoString.Count;
   string[]  astrLable=SysInfoString.lables;
   string[]  astrValues=SysInfoString.values;
   for(int i=0;i<iCount;i++)
   {
    grs.DrawString(astrLable[i],Font,brush,0,i*cySpace);
    grs.DrawString(astrValues[i],Font,brush,cxCol,i*cySpace); } 
  } }
}
如上所示,通过从Control继承来的CreateGraphics 方法得到有关本控件显示的的Graphics 对象.这和Delphi

有所不同,Delphi许多控件都有Canvas.

阅读更多
个人分类: C#基础
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭