7.C#编程学习——属性

7.C#编程学习——属性

代码如下:

usingSystem;

usingSystem.Drawing;

usingSystem.Windows.Forms;

classSysInfoList : Form

{

    readonlyfloat cxCol;

    readonlyint cySpace;

 

    publicstaticvoid Main()

    {

        Application.Run(newSysInfoList());

    }

    public SysInfoList()

    {

        Text = "System Information: List";

        BackColor = SystemColors.Window;

        ForeColor = SystemColors.WindowText;

 

        Graphics grfx = CreateGraphics();

        SizeF sizef = grfx.MeasureString(" ", Font);

        cxCol = sizef.Width + SysInfoStrings.MaxLabelWidth(grfx, Font);

        grfx.Dispose();

        cySpace = Font.Height;

    }

    protectedoverridevoid OnPaint(PaintEventArgs pea)

    {

        Graphics grfx = pea.Graphics;

        Brush brush = newSolidBrush(ForeColor);

        int iCount = SysInfoStrings.Count;

        string[] astrLabels = SysInfoStrings.Labels;

        string[] astrValues = SysInfoStrings.Values;

 

        for (int i = 0; i < iCount;i++)

        {

            grfx.DrawString(astrLabels[i],Font, brush,

                            0, i * cySpace);

            grfx.DrawString(astrValues[i],Font, brush,

                            cxCol, i *cySpace);

        }

    }

}

SysInfoStrings.cs如下

//---------------------------------------------

// SysInfoStrings.cs ?2001 byCharles Petzold

//---------------------------------------------

usingSystem;

usingSystem.Drawing;

usingSystem.Windows.Forms;

 

classSysInfoStrings

{

    publicstaticstring[] Labels

    {

        get

        {

            returnnewstring[]

               {

                    "ArrangeDirection",

                    "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",

                    "MenuFont",

                    "MenuHeight",

                    "MidEastEnabled",

                    "MinimizedWindowSize",

                    "MinimizedWindowSpacingSize",

                    "MinimumWindowSize",

                    "MinWindowTrackSize",

                    "MonitorCount",

                    "MonitorsSameDisplayFormat",

                    "MouseButtons",

                    "MouseButtonsSwapped",

                    "MousePresent",

                    "MouseWheelPresent",

                    "MouseWheelScrollLines",

                    "NativeMouseWheelSupport",

                    "Network",

                    "PenWindows",

                    "PrimaryMonitorMaximizedWindowSize",

                    "PrimaryMonitorSize",

                    "RightAlignedMenus",

                    "Secure",

                    "ShowSounds",

                    "SmallIconSize",

                    "ToolWindowCaptionButtonSize",

                    "ToolWindowCaptionHeight",

                    "UserDomainName",

                    "UserInteractive",

                    "UserName",

                    "VerticalScrollBarArrowHeight",

                    "VerticalScrollBarThumbHeight",

                    "VerticalScrollBarWidth",

                    "VirtualScreen",

                    "WorkingArea",

               };

        }

    }

    publicstaticstring[] Values

    {

        get

        {

            returnnewstring[]

               {

               SystemInformation.ArrangeDirection.ToString(),

               SystemInformation.ArrangeStartingPosition.ToString(),

               SystemInformation.BootMode.ToString(),

               SystemInformation.Border3DSize.ToString(),

               SystemInformation.BorderSize.ToString(),

               SystemInformation.CaptionButtonSize.ToString(),

               SystemInformation.CaptionHeight.ToString(),

               SystemInformation.ComputerName,

               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.MenuFont.ToString(),

               SystemInformation.MenuHeight.ToString(),

               SystemInformation.MidEastEnabled.ToString(),

               SystemInformation.MinimizedWindowSize.ToString(),

               SystemInformation.MinimizedWindowSpacingSize.ToString(),

               SystemInformation.MinimumWindowSize.ToString(),

               SystemInformation.MinWindowTrackSize.ToString(),

               SystemInformation.MonitorCount.ToString(),

               SystemInformation.MonitorsSameDisplayFormat.ToString(),

               SystemInformation.MouseButtons.ToString(),

               SystemInformation.MouseButtonsSwapped.ToString(),

               SystemInformation.MousePresent.ToString(),

               SystemInformation.MouseWheelPresent.ToString(),

               SystemInformation.MouseWheelScrollLines.ToString(),

               SystemInformation.NativeMouseWheelSupport.ToString(),

               SystemInformation.Network.ToString(),

               SystemInformation.PenWindows.ToString(),

               SystemInformation.PrimaryMonitorMaximizedWindowSize.ToString(),

               SystemInformation.PrimaryMonitorSize.ToString(),

               SystemInformation.RightAlignedMenus.ToString(),

               SystemInformation.Secure.ToString(),

               SystemInformation.ShowSounds.ToString(),

               SystemInformation.SmallIconSize.ToString(),

               SystemInformation.ToolWindowCaptionButtonSize.ToString(),

               SystemInformation.ToolWindowCaptionHeight.ToString(),

               SystemInformation.UserDomainName,

              SystemInformation.UserInteractive.ToString(),

               SystemInformation.UserName,

               SystemInformation.VerticalScrollBarArrowHeight.ToString(),

               SystemInformation.VerticalScrollBarThumbHeight.ToString(),

               SystemInformation.VerticalScrollBarWidth.ToString(),

               SystemInformation.VirtualScreen.ToString(),

               SystemInformation.WorkingArea.ToString(),

               };

        }

    }

    publicstaticint Count

    {

        get

        {

            return Labels.Length;

        }

    }

    publicstaticfloat MaxLabelWidth(Graphics grfx, Font font)

    {

        return MaxWidth(Labels, grfx, font);

    }

    publicstaticfloat MaxValueWidth(Graphics grfx, Font font)

    {

        return MaxWidth(Values, grfx, font);

    }

    staticfloat 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;

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值