文本输出中的练习

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值