I Love You !

來源:互聯網
上載者:User

一個很無聊的小程式:

下面直接給出代碼

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).

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.