回 帖 发 新 帖 刷新版面

主题:帮帮忙,鼠标事件(绘画问题)

public partial class Form1 : Form
    {
        bool shouldpaint = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void Painter_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            shouldpaint = true;
        }
        private void Painter_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            shouldpaint = false;
        }
        private void Painter_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (shouldpaint)
            {
                Graphics graphics = CreateGraphics();
                graphics.FillEllipse(new SolidBrush(Color.BlueViolet), e.X, e.Y, 8, 8);
            }
        }
    }
我想在窗体上面画画,但就是画不出来,运行后也没有提示出错,这是怎么回事啊? 
高手指点指点啊!~~

回复列表 (共2个回复)

沙发

namespace WindowsApplication3
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Control;
            this.ClientSize = new System.Drawing.Size(522, 428);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }

        #endregion
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
    public class Form1 : Form
    {
        
        bool shouldpaint = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void Painter_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            shouldpaint = true;
        }
        private void Painter_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            shouldpaint = false;
        }
        private void Painter_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            
            if (shouldpaint)
            {
                Graphics graphics = CreateGraphics();
                graphics.FillEllipse(new SolidBrush(Color.BlueViolet), e.X, e.Y,4,4);
            }
        }
    }
}
全部代码了!!!

板凳

两个命名空间是否连接上?

我来回复

您尚未登录,请登录后再回复。点此登录或注册