当前位置:编程学习 > C#/ASP.NET >>

C# GDI+画图问题,程序运行后无法看到结果。急!!!!谢谢!

下面程序运行后无法看到结果:
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_Load(object sender, EventArgs e)
        {

        }
        private void Form1_MouseMove(object sender, System.Windows .Forms .MouseEventArgs   e)
        {
            Point p = new Point(e.X ,e.Y);
            Rectangle r;

            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 ;
        }
        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs 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);
        }
    }
} --------------------编程问答-------------------- mark --------------------编程问答-------------------- 没问题啊!LZ怎么会看不到呢? --------------------编程问答-------------------- 照你的意思,vb中试了一下:

Public Class Form1

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        Dim p As Point = New Point(e.X, e.Y)

        If New Rectangle(0, 0, 100, 100).Contains(p) Then
            Me.Cursor = Cursors.Cross
        ElseIf New Rectangle(100, 0, 100, 100).Contains(p) Then
            Me.Cursor = Cursors.Hand
        ElseIf New Rectangle(0, 100, 100, 100).Contains(p) Then
            Me.Cursor = Cursors.VSplit
        ElseIf New Rectangle(100, 100, 100, 100).Contains(p) Then
            Me.Cursor = Cursors.UpArrow
        Else
            Me.Cursor = Cursors.Default
        End If
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As Graphics = 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)
    End Sub
End Class

没有问题,可以正常显示四个不同填充色的矩形框,并且鼠标移动到每个矩形框显示不同的光标。 --------------------编程问答-------------------- 事件丢失了? --------------------编程问答-------------------- 谢谢大家!是不是我运行环境出了问题?!!不过事件丢失了,是什么意思啊? --------------------编程问答-------------------- 高手们,运行环境重新安装了还是显示不出来,怎么办啊? --------------------编程问答-------------------- 还没解决呢。估计不是代码的问题了。 --------------------编程问答-------------------- 把你的exe文件拷贝到另外一台电脑上试试看吧,判断一下是不是你的运行环境的问题。呵呵 --------------------编程问答-------------------- 没有事件,拿来丢失.
还是按照wzuomin的方法检查一下先 --------------------编程问答-------------------- 依据下面代码把windows自动生成的代码修改一下吧:

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

} --------------------编程问答-------------------- wzuomin确实是高手!!佩服!!怎么给你分数? --------------------编程问答-------------------- study --------------------编程问答-------------------- 没问题的。我试了一下。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,