| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1166 人关注过本帖
标题:运行后没有图像!谢谢!
只看楼主 加入收藏
jay520
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-2-11
结帖率:83.33%
收藏
已结贴  问题点数:20 回复次数:9 
运行后没有图像!谢谢!
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace basicgraphic
{
    public partial class frmMain : Form
    {
        int fg;
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            fg = 0;
            this.Invalidate();
        }
        private void btnCir_Click(object sender, EventArgs e)
        {
            fg = 1;
            this.Invalidate();
        }
        private void btnEllipse_Click(object sender, EventArgs e)
        {

            fg = 2;
            this.Invalidate();
        }
        private void btnPie_Click(object sender, EventArgs e)
        {

            fg = 3;
            this.Invalidate();
        }

        private void btnLine_Click(object sender, EventArgs e)
        {

            fg = 4;
            this.Invalidate();
        }

        private void btnArc_Click(object sender, EventArgs e)
        {

            fg = 5;
            this.Invalidate();
        }

        private void btn_Click(object sender, EventArgs e)
        {

            fg = 6;
            this.Invalidate();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen1 = new Pen(Color.Blue, 3);
            switch (fg)
            {
                case 0:
                    g.Clear(Color.Gainsboro);
                    break;
                case 1:
                    g.DrawEllipse(pen1, 50, 50, 150, 150);
                    break;

                case 2:
                    g.DrawEllipse(pen1, 50, 50, 300, 200);
                    break;
                case 3:
                    g.DrawLine(pen1, 50, 100, 300, 100);
                    break;
                case 4:
                    g.DrawArc(pen1, 50, 50, 200, 300, 180, 90);
                    break;
                case 5:
                    g.DrawRectangle(pen1, 50, 50, 200, 150);
                    break;
                case 6:
                    g.DrawPie(pen1, 100, 100, 300, 200, 225, 90);
                    break;
            }
        }
    }
}
windows应用程序 7个Button 1.btnClear  清除2.btnCir 圆 3.btnEllipse 椭圆 4.benPie扇形   5.btnLine 直线6.btnArc弧线 7.btn矩形  
还有我自己加了个panel..书本没的!还有private void panel1_Paint(object sender, PaintEventArgs e) 书本这句是
private void femMain_Paint(object sender, PaintEventArgs e)
生成成功..却运行不出图像!点解!
搜索更多相关主题的帖子: private 
2011-03-09 20:57
xydddaxia
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:33
帖 子:466
专家分:2307
注 册:2009-3-20
收藏
得分:4 
Graphics g = this.panel1.CreateGraphics();

站在春哥的肩膀上
2011-03-10 08:50
zkmhywgsym
Rank: 2
等 级:论坛游民
帖 子:38
专家分:98
注 册:2011-3-5
收藏
得分:4 
this.Invalidate();
这调用的什么啊,没见过这个函数
2011-03-10 16:28
浩凡儿
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:101
专家分:394
注 册:2010-10-30
收藏
得分:4 
这个就只是个控制台应用程序呀
2011-03-10 16:35
vxbb
Rank: 6Rank: 6
等 级:侠之大者
帖 子:163
专家分:440
注 册:2008-8-18
收藏
得分:4 
            Graphics g = e.Graphics;
or :
            Graphics g = panel1.CreateGraphics();

QQ:491697374  Mail:vxbb@
2011-03-10 17:41
jay520
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-2-11
收藏
得分:0 
回复 2楼 xydddaxia
basicgraphic frmMain 并不包含Pen1
2011-03-10 19:14
jay520
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-2-11
收藏
得分:0 
回复 5楼 vxbb
这两个句子貌似不能同时用!e重哪里来的!
2011-03-10 19:20
xydddaxia
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:33
帖 子:466
专家分:2307
注 册:2009-3-20
收藏
得分:0 
如果是在Form上绘图
Graphics g = this.CreateGraphics();
如果在Panel1上绘图
Graphics g = this.Panel1.CreateGraphics();

站在春哥的肩膀上
2011-03-10 20:00
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:4 
程序代码:
using System;
using System.Collections.Generic;
using  System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace basicgraphic
{
    public partial class Form1 : Form
    {
        int fg=1;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            if (fg >= 6)'这里仅作测试之用
            {
                fg = 0;
            }
            else
            {
                fg = fg + 1;
            }
            this.panel1.Invalidate();'这个很关键:触发panel1的无效,让其重画

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = this.panel1.CreateGraphics();'这里也是比较重要的
            Pen pen1 = new Pen(Color.Blue, 3);
            switch (fg)
            {
                case 0:
                    g.Clear(Color.Gainsboro);
                    break;
                case 1:
                    g.DrawEllipse(pen1, 50, 50, 150, 150);
                    break;

                case 2:
                    g.DrawEllipse(pen1, 50, 50, 300, 200);
                    break;
                case 3:
                    g.DrawLine(pen1, 50, 100, 300, 100);
                    break;
                case 4:
                    g.DrawArc(pen1, 50, 50, 200, 300, 180, 90);
                    break;
                case 5:
                    g.DrawRectangle(pen1, 50, 50, 200, 150);
                    break;
                case 6:
                    g.DrawPie(pen1, 100, 100, 300, 200, 225, 90);
                    break;
            }

        }
    }
}
2011-03-11 12:32
vxbb
Rank: 6Rank: 6
等 级:侠之大者
帖 子:163
专家分:440
注 册:2008-8-18
收藏
得分:0 
以下是引用jay520在2011-3-10 19:20:32的发言:

这两个句子貌似不能同时用!e重哪里来的!

            Graphics g = e.Graphics;
      or :
            Graphics g = panel1.CreateGraphics();
当然不能同时用了,所以 我写了 " or:" .

e 是事件→  private void panel1_Paint(object sender, PaintEventArgs e);

QQ:491697374  Mail:vxbb@
2011-03-17 16:39
快速回复:运行后没有图像!谢谢!
数据加载中...
 
   



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

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