zoukankan      html  css  js  c++  java
  • c# winform 应用编程代码总结 5

    18、文本的旋转显示

           private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
            {
                Graphics g =e.Graphics;
                g.SmoothingMode=SmoothingMode.AntiAlias;
                //声明并初始化Graphics对象g
                string tempstr = "Hello C#";
                //取得要显示的文字
                for(int i=0;i<361;i=i+10)
                {
                    g.TranslateTransform(150, 150);
                    g.RotateTransform(i);
                    //将指定的旋转用于g的变换矩阵
                    //将指定的平移添加到g的变换矩阵前
                    Brush myBrush=Brushes.Blue;
                    g.DrawString(tempstr, this.Font, myBrush, 60, 0);
                    //显示旋转文字
                    g.ResetTransform();
                    //将g的全局变换矩阵重置为单位矩阵
                }
            }

              image

    19、阴影效果的文字

               Graphics g=e.Graphics
                Font myFont;
                myFont=new Font("SansSerif",40); 
                
                SolidBrush textShadowBrush = new SolidBrush(Color.FromArgb(70, Color.Blue));

                g.DrawString("Hello C#",myFont,Brushes.Blue, 25, 25 );
                g.DrawString("Hello C#",myFont,textShadowBrush, 30, 30);

                image

    20、图案填充的文字

                Image textImage = new Bitmap("..\\..\\Texture.ICO");
                TextureBrush textTextureBrush = new TextureBrush(textImage);
                Font myFont=new Font("SansSerif",50);
                e.Graphics.DrawString("Hello C#", myFont, textTextureBrush, 10, 20 );

               image

    21、将彩色图片转换为灰度图片

            Bitmap bmp;
            private void button1_Click(object sender, System.EventArgs e)
            {
                if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
                {
                    bmp=new Bitmap(this.openFileDialog1.FileName);
                    for (int i=0;i<bmp.Width-1;i++)
                    {
                        for(int j=0;j<bmp.Height-1;j++)
                        {
                            Color Color1=bmp.GetPixel(i,j);
                            int rgb=(Color1.R+Color1.G+Color1.B)/3;
                            //颜色处理
                            bmp.SetPixel(i,j,Color.FromArgb(rgb,rgb,rgb));
                        }
                    }
                    this.pictureBox1.Image=bmp;
                }
            }

            private void Form1_Load(object sender, System.EventArgs e)
            {
                this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage;
            }

           image

    本系列文章是作者学习《Visual C#.NET 应用编程150例》(源码)心得笔记,欢迎转载,请注明原文地址,如有疑问,可以通过 278250658@qq.com 联系作者本人。

  • 相关阅读:
    【转】如何高效地阅读技术类书籍与博客
    测试站点大全
    【转】软件测试面试- 购物车功能测试用例设计
    div+css 定位浅析
    C# Enum,Int,String的互相转换
    sqlserver 空间数据类型
    系统学习sqlserver2012 一
    sql查询数据库中所有表的记录条数,以及占用磁盘空间大小。
    linux网站推荐
    匿名用户访问sharepoint2010中的列表
  • 原文地址:https://www.cnblogs.com/syxchina/p/2197281.html
Copyright © 2011-2022 走看看