I Love You !

一个很无聊的小程序:

下面直接给出代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;

namespace WFADeskTopShow
{
    public partial class DesktopWindow : Form
    {
        public DesktopWindow()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.ShowInTaskbar = false;
            this.Load += new EventHandler(this_Load);
            p1.Size = new Size(40, 40);
            this.lb1.Location = new Point(30, 75);
            this.lb2.Location = new Point(30, 100);
            this.tb1.Location = new Point(150, 75);
            this.tb2.Location = new Point(150, 100);
            this.bt1.Location = new Point(50, 125);
            this.bt2.Location = new Point(150, 125);
            p1.Location = new Point(190, 190);
            p1.BorderStyle = BorderStyle.Fixed3D;
            this.Controls.Add(lb1);
            this.Controls.Add(lb2);
            this.Controls.Add(tb1);
            this.Controls.Add(tb2);
            this.Controls.Add(bt1);
            this.Controls.Add(bt2);
            this.Controls.Add(p1);
            this.bt1.Click += new EventHandler(bt1_Click);
            this.bt2.Click += new EventHandler(bt2_Click);
            this.p1.Click += new EventHandler(p1_Click);
            this.BackColor = Color.Transparent;

        }

        void p1_Click(object sender, EventArgs e)
        {
            cd.ShowDialog();
            {
                p1.BackColor = cd.Color;
                fontColor = this.p1.BackColor;
            };
        }

        void bt2_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
            Application.ExitThread();
        }

        void control_Paint(object sender, PaintEventArgs e)
        {
            Font f = new Font("宋体",stringSize);//System.Drawing.SystemColors.Control&&fontColor==Color.Transparent
            if (fontColor == SystemColors.Control)
            {
                fontColor = Color.Cyan;
                bt2.BackColor = fontColor;
                bt2.Size = new Size(25, 18);
                bt2.Text = "关";
            }
            SolidBrush sb = new SolidBrush(fontColor);
            e.Graphics.DrawString(s, f, sb, this.Width / 2 -400 , this.Height / 2 - 400);
            f.Dispose();
            sb.Dispose();
        }

        void bt1_Click(object sender, EventArgs e)
        {
            if (tb1.Text != "")
            {
                s = tb1.Text;
                try
                {
                    stringSize = Convert.ToInt32(tb2.Text.ToString().Trim());
                    this.TransparencyKey = System.Drawing.SystemColors.Control;
                    this.BackColor = System.Drawing.SystemColors.Control;
                    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                    this.WindowState = FormWindowState.Maximized;
                    //this.lb1.Hide();
                    //this.tb2.Hide();
                    //this.tb1.Hide();
                    //this.tb2.Hide();
                    //this.bt1.Hide();
                    fontColor = p1.BackColor;
                    p1.Dispose();
                    cd.Dispose();
                    this.lb1.Dispose();
                    this.lb2.Dispose();
                    this.tb1.Dispose();
                    this.tb2.Dispose();
                    this.bt1.Dispose();
                    this.bt2.Location = new Point(0, 0);
                    bt2.FlatStyle = FlatStyle.Popup;
                    this.Controls.Add(control);
                    control.Location = new Point(0, 0);
                    control.Size = this.Size;
                    this.control.Paint += new PaintEventHandler(control_Paint);
                }
                catch
                {
                    MessageBox.Show("字体大小应该数值型的比如“100”是请修改字体大小!");
                }
            }
            else
            {
                MessageBox.Show("请输入内容");
            }
           
           
        }
        void this_Load(object sender, EventArgs e)
        {
            this.lb1.Text = "请输入内容:";
            this.bt1.Text = "确定";
            this.bt2.Text = "取消";
            this.lb2.Text = "请输入大小:";
        }

        Label lb1 = new Label();
        Label lb2 = new Label();
        TextBox tb1 = new TextBox();
        TextBox tb2 = new TextBox();
        Button bt1 = new Button();
        Button bt2 = new Button();
        Panel p1 = new Panel();
        Control control = new Control();
        ColorDialog cd = new ColorDialog();
        static string s;
        static int stringSize;
        static Color fontColor;


    }
}

 

效果概览:

(1).

(2).

posted @ 2010-04-05 22:03  SoarNo1  阅读(208)  评论(0编辑  收藏  举报