是不是界面没有刷新,所以没有执行Form1_Paint,试一下,如果你切换一下界面就显示图象了的话,那就是没有刷新的原因了。

解决方案 »

  1.   

    你以上的代码没有问题。轻松开发软件,详见:http://www.psec.net.cn
      

  2.   

    override void onpaint()  重载onpaint函数
      

  3.   

    lz又开了一帖啊。呵呵丢失了事件,这么着吧。代码编辑器中找到 windows窗体设计器生成的代码,照我下面代码修改一下吧:#region Windows 窗体设计器生成的代码        /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                this.button1 = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(205, 238);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 0;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(292, 273);
                this.Controls.Add(this.button1);
                this.Name = "Form1";
                this.Text = "Form1";//主要是下面两句。呵呵
                this .MouseMove += new System.Windows.Forms.MouseEventHandler (this.Form1_MouseMove );
                this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
                this.ResumeLayout(false);        }        #endregion
      

  4.   

    上面那个Button1的就不用了。呵呵private void InitializeComponent()
            {
                this.SuspendLayout();
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(292, 273);
                this.Name = "Form1";
                this.Text = "Form1";
                this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
                this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
                this.Load += new System.EventHandler(this.Form1_Load);
                this.ResumeLayout(false);        }
      

  5.   

    wzuomin怎么给你加分阿,太感谢了!!能否再告诉我原因就十分感谢了!!
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace gdiplustest0
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
           
            private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                Point p = new Point(e.X, e.Y);
                if (new Rectangle(0, 0, 100, 100).Contains(p))           
                    this.Cursor = Cursors.Cross;              
                else if (new Rectangle(100, 0, 100, 100).Contains(p))
                    this.Cursor = Cursors.Hand;
                else if (new Rectangle(0, 100, 100, 100).Contains(p))
                    this.Cursor = Cursors.VSplit;
                else if (new Rectangle(100, 100, 100, 100).Contains(p))
                    this.Cursor = Cursors.UpArrow;
                else
                    this.Cursor = Cursors.Default;
            }
            protected override void  OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                Graphics g = e.Graphics;
                g.FillRectangle(Brushes.Blue, 0, 0, 100, 100);
                g.FillRectangle(Brushes.Red, 100, 0, 100, 100);
                g.FillRectangle(Brushes.Yellow, 0, 100, 100, 100);
                g.FillRectangle(Brushes.Green, 100, 100, 100, 100);
            }
        }
    }
      

  7.   

    像这样写就一点都没有问题了
    因为在生成窗体时,需要重新画窗体。你的程序需要安装一个Paint事件来重画你的窗体
    或者重载一下OnPaint()方法就可以了。