SysinfoPanel构造时定义了个面板,可是构造函数中定义了:Panel panel = new Panel();
那么构造结束时 panel 不是就销毁了吗???
一直从事c++,刚看c# 没明白。怎么可以这样?代码如下:class SysinfoPanel:Form
{
readonly float cxCol;
readonly int cySpace;
public static void Main()
{
Application.Run(new SysinfoPanel());
}
public SysinfoPanel()
{
Text = "Systim information :Panel";
BackColor = SystemColors.ButtonFace;
ForeColor = SystemColors.WindowText;
AutoScroll = true;
AutoScrollMargin = new Size(10, 10);
Graphics g = CreateGraphics();
SizeF sizef = g.MeasureString(" ",Font);
cxCol = sizef.Width + SysinfoStrings.MaxLabelWidth(g, Font);
cySpace = Font.Height;
//creat a panel
Panel panel = new Panel();
panel.Parent = this;
panel.Paint += new PaintEventHandler(PanelPaint);
panel.Location = Point.Empty;
panel.BackColor = Color.Honeydew;
panel.Size = new Size(
(int)Math.Ceiling(cxCol + SysinfoStrings.MaxValueWidth(g, Font)),
(int)Math.Ceiling((double)cySpace * SysinfoStrings.Count));
g.Dispose();
}
void PanelPaint(object obj, PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush brush = new SolidBrush(ForeColor);
int iCount = SysinfoStrings.Count;
string[] astrLabels = SysinfoStrings.Labels;
string[] astrValues = SysinfoStrings.Values;
for (int i = 0 ; i< iCount; i++)
{
g.DrawString(astrLabels[i],Font,brush,0,i*cySpace);
g.DrawString(astrValues[i],Font,brush,cxCol,i*cySpace);
}
}
}
解决方案 »
- 如何查看.net中类的继承关系?
- [向all]说说你对C#和.net的理解.
- 【全部分数!求救】如何实现richTextBox的隔行现实?
- 有人对金山词霸的生词本研究过吗?
- vc++转c#的问题,LPVOID到底是什么类型?
- 菜鸟提问:一个DataGrid,有一行,现想让这一行能修改,但不能加新行,如何做?谢谢
- 问一个关于用C#读取关于SQL数据类型的问题
- 未处理 System.Data.SqlClient.SqlException
- 怎么进行面向对象的分析和设计啊
- **现在学C#或是C++好!请给意见!**
- 帖子置顶的问题
- 能不能在bindingnavigator中添加一个datetimepicker控件啊?
这样垃圾收集器就会知道panel还有引用 就不会收集他了 猜想而已。。