学习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();

        }

 

 

 

 

你可能感兴趣的:(object,String,图形,GDI+)