奇怪现象: 程序最大化后,快速拖动分割条,图片有时候不能正常显示.... 简单程序,看原程序。
//谢谢大家!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace testimage
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private string strPath;
private Image imx;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
strPath = Path.GetDirectoryName( Application.ExecutablePath );
imx = Image.FromFile( strPath + @"\a.bmp" );
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.treeView1 = new System.Windows.Forms.TreeView();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.panel1.Controls.Add(this.treeView1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(144, 557);
this.panel1.TabIndex = 0;
this.panel1.SizeChanged += new System.EventHandler(this.panel1_SizeChanged);
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// treeView1
//
this.treeView1.ImageIndex = -1;
this.treeView1.ItemHeight = 14;
this.treeView1.Location = new System.Drawing.Point(0, 25);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(144, 528);
this.treeView1.TabIndex = 2;
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(144, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 557);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Desktop;
this.ClientSize = new System.Drawing.Size(632, 557);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
this.Load += new System.EventHandler(this.Form1_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImageUnscaled (this.imx, this.panel1.Size.Width -50, 2);
}
private void panel1_SizeChanged(object sender, System.EventArgs e)
{
this.treeView1.Size = new Size (this.panel1.Size.Width - 4, this.panel1.Size.Height -25);
this.panel1.Invalidate();
//this.Refresh();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
private void Form1_SizeChanged(object sender, System.EventArgs e)
{
this.panel1.Invalidate();
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.treeView1.Location = new System.Drawing.Point(0,25);
}
}
}