| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 363 人关注过本帖
标题:color的問題請大家教教謝謝
只看楼主 加入收藏
xp幻影
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-8-11
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:4 
color的問題請大家教教謝謝
类里面的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace _2011._11._04
{
    public class Lines0
    {
        Point _FirstPoint0 = Point.Empty;
        public Point FirstPoint0
        {
            get { return _FirstPoint0; }
            set { _FirstPoint0 = value; }
        }
        Point _secordPoint0 = Point.Empty;
        public Point SecordPoint0
        {
            get { return _secordPoint0; }
            set { _secordPoint0 = value; }
        }
    }
}
Form1里面的
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _2011._11._04
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //====== 变量 命名
        Graphics g0;
        Lines0 currLine0 = null;
        List<Lines0> MyLines0 = new List<Lines0>();
        private Color abc;
        string sun = "";
        private void Form1_Load(object sender, EventArgs e)
        {
            g0 = this.CreateGraphics();
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (currLine0 != null)
            {
                currLine0.SecordPoint0 = new Point(e.X, e.Y);
                this.Invalidate();
                currLine0 = new Lines0();
                currLine0.SecordPoint0 = new Point(e.X, e.Y);
                currLine0.FirstPoint0 = new Point(e.X, e.Y);
                MyLines0.Add(currLine0);
            }
        }
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (currLine0 == null) return;
            {
                currLine0.SecordPoint0 = new Point(e.X, e.Y);
                currLine0 = null;
            }
        }
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            currLine0 = new Lines0();
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            for (int i = 0; i < MyLines0.Count; i++)
            {
                if (sun == "")
                {
                    g0.DrawLine(Pens.Black, MyLines0[i].FirstPoint0, MyLines0[i].SecordPoint0);
                }
                if (sun == "bb")
                {
                    Pen ppen = new Pen(this.abc, 1);
                    g0.DrawLine(ppen, MyLines0[i].FirstPoint0, MyLines0[i].SecordPoint0);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sun = "bb";
            DialogResult mycolor = colorDialog1.ShowDialog();
            if (mycolor == DialogResult.OK)//确定事件响应
            {
                abc = colorDialog1.Color;
            }
            if (mycolor == DialogResult.Cancel)//取消事件响应
            {
                this.abc = Color.Black;
            }
        }
    }
}
搜索更多相关主题的帖子: public return color 
2011-11-04 11:50
xp幻影
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-8-11
收藏
得分:0 
这个是个画笔,问題是第一笔画的是黑色但按z自定义颜色选择后没画第一笔就变色吧!
2011-11-04 11:59
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:10 
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            for (int i = 0; i < MyLines0.Count; i++)
            {
                if (sun == "")
                {
                    g0.DrawLine(Pens.Black, MyLines0[i].FirstPoint0, MyLines0[i].SecordPoint0);
                }
                if (sun == "bb")
                {
                    Pen ppen = new Pen(this.abc, 1);
                    g0.DrawLine(ppen, MyLines0[i].FirstPoint0, MyLines0[i].SecordPoint0);
                }
            }
        }
因为你所有画过的线的坐标都在MyLines0中,当你改变颜色以后,又用新的颜色把之前画过的线又重新画了一次
2011-11-04 13:12
xp幻影
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-8-11
收藏
得分:0 
回复 3楼 yhlvht
有什麼方法可以改嗎?教我一下,謝謝
2011-11-07 08:25
xp幻影
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-8-11
收藏
得分:0 
回复 4楼 xp幻影
我想不到辦法了     我是個新手    教教吧
2011-11-07 08:27
快速回复:color的問題請大家教教謝謝
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037222 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved