学习dotnet第四课关于绘图的自己做的实例源代码,存在这儿,方便复习.

实心画笔填充的图形

 

   private void buttonUseBrush_Click(object sender, EventArgs e)
        {
            Graphics g = panel1.CreateGraphics();
            Brush fillBrush = new SolidBrush(Color.Red);
            g.FillEllipse(fillBrush, panel1.ClientRectangle);
           
            g.Dispose();

        }

 

颜色使用,设置背景色

 

      private void buttonSetBkColor_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                Color clr = colorDialog1.Color;
                this.BackColor = clr;

              
            }

 

文件对话框使用,画板,图像填充

 


        private void Form_Paint_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            string drawString = "Hello GDI+ ";
            Font songTi = new Font( "宋体", 20 );
            Brush redBrush = Brushes.Red;
            PointF pointDraw = new PointF(10, 10);

            g.DrawString(drawString, songTi, redBrush, pointDraw );
            g.Dispose();
        }

        private void buttonSelectFile_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK )
            {
                String fileName = openFileDialog1.FileName;
                Graphics g = panelFile.CreateGraphics();
                Bitmap bg = new Bitmap(fileName);
                Graphics fromBg = Graphics.FromImage(bg);

                string strText = System.IO.Path.GetFileName(fileName);
                Font fontSongTi = new Font("宋体", 20);
                Brush redBrushes = Brushes.Red;
                PointF pointPt = new PointF( 10, 10 );
                fromBg.DrawString(strText, fontSongTi, redBrushes, pointPt );

                PointF newPoint = new PointF(0, 0);
                g.DrawImage(bg, panelFile.ClientRectangle );

                g.Dispose();
            }

        }

 

画两个简单的圆,一个在From 上, 一个是Panel 上

 

   private void buttonOnForm_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen redPen = Pens.Red;

            g.DrawEllipse( redPen, this.ClientRectangle );
            g.Dispose();

        }

        private void buttonOnControl_Click(object sender, EventArgs e)
        {
            Graphics g = richTextBoxDraw.CreateGraphics();
            Pen bluePen = Pens.Blue;

            g.DrawEllipse(bluePen, richTextBoxDraw.ClientRectangle);
            g.Dispose();

        }

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值