本文主要是介绍一个程序员对领导应该有的基本告白,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一个程序员眼中对领导应该有的基本告白
一、 项目说明
开发环境:VS2019
最近闲来无事,收到隔壁求援,需求:在月底向领导申请涨工资,
本来是拒绝的,后来瞩以重金,我就被迫答应了
于是乎,
开始重操旧业,继续发扬C#光荣使命,
first step:在网上荡了几张图片
然后嘞…开始思索…思索…思索…
two yearsr late…
就得到了下面的结果了,不说了,往下看:
二、项目结构
三、实现效果
四、Program.cs
老计划,先上Program.cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 辞职申请书
{static class Program{/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form1());}}
}
五、界面设计
设置见面元素布局,代码如下:
namespace 辞职申请书
{partial class Form1{/// <summary>/// 必需的设计器变量。/// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// 清理所有正在使用的资源。/// </summary>/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// <summary>/// 设计器支持所需的方法 - 不要修改/// 使用代码编辑器修改此方法的内容。/// </summary>private void InitializeComponent(){System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));this.label1 = new System.Windows.Forms.Label();this.panel1 = new System.Windows.Forms.Panel();this.label2 = new System.Windows.Forms.Label();this.pictureBox2 = new System.Windows.Forms.PictureBox();this.button3 = new System.Windows.Forms.Button();this.button2 = new System.Windows.Forms.Button();this.button1 = new System.Windows.Forms.Button();this.panel2 = new System.Windows.Forms.Panel();this.label4 = new System.Windows.Forms.Label();this.label3 = new System.Windows.Forms.Label();this.pictureBox1 = new System.Windows.Forms.PictureBox();this.roundButton2 = new 辞职申请书.RoundButton();this.roundButton1 = new 辞职申请书.RoundButton();this.panel1.SuspendLayout();((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();this.panel2.SuspendLayout();((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();this.SuspendLayout();// // label1// this.label1.AutoSize = true;this.label1.Font = new System.Drawing.Font("新宋体", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label1.Location = new System.Drawing.Point(16, 20);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(303, 35);this.label1.TabIndex = 3;this.label1.Text = "尊敬的各位领导:";// // panel1// this.panel1.Controls.Add(this.label2);this.panel1.Controls.Add(this.pictureBox2);this.panel1.Controls.Add(this.button3);this.panel1.Controls.Add(this.button2);this.panel1.Controls.Add(this.button1);this.panel1.Location = new System.Drawing.Point(0, 0);this.panel1.Name = "panel1";this.panel1.Size = new System.Drawing.Size(885, 40);this.panel1.TabIndex = 4;this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);// // label2// this.label2.AutoSize = true;this.label2.Font = new System.Drawing.Font("新宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label2.Location = new System.Drawing.Point(46, 11);this.label2.Name = "label2";this.label2.Size = new System.Drawing.Size(129, 19);this.label2.TabIndex = 4;this.label2.Text = "涨工资申请书";// // pictureBox2// this.pictureBox2.BackgroundImage = global::辞职申请书.Properties.Resources._333;this.pictureBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;this.pictureBox2.Location = new System.Drawing.Point(0, 0);this.pictureBox2.Name = "pictureBox2";this.pictureBox2.Size = new System.Drawing.Size(40, 40);this.pictureBox2.TabIndex = 3;this.pictureBox2.TabStop = false;// // button3// this.button3.BackColor = System.Drawing.Color.White;this.button3.Cursor = System.Windows.Forms.Cursors.Hand;this.button3.FlatAppearance.BorderSize = 0;this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.button3.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.button3.Location = new System.Drawing.Point(765, 0);this.button3.Name = "button3";this.button3.Size = new System.Drawing.Size(40, 40);this.button3.TabIndex = 2;this.button3.Text = "-";this.button3.UseVisualStyleBackColor = false;this.button3.Click += new System.EventHandler(this.button3_Click);// // button2// this.button2.BackColor = System.Drawing.Color.White;this.button2.Cursor = System.Windows.Forms.Cursors.Hand;this.button2.FlatAppearance.BorderSize = 0;this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.button2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.button2.Location = new System.Drawing.Point(805, 0);this.button2.Name = "button2";this.button2.Size = new System.Drawing.Size(40, 40);this.button2.TabIndex = 1;this.button2.Text = "□";this.button2.UseVisualStyleBackColor = false;this.button2.Click += new System.EventHandler(this.button2_Click);// // button1// this.button1.BackColor = System.Drawing.Color.White;this.button1.Cursor = System.Windows.Forms.Cursors.Hand;this.button1.FlatAppearance.BorderSize = 0;this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.button1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.button1.Location = new System.Drawing.Point(845, 0);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(40, 40);this.button1.TabIndex = 0;this.button1.Text = "×";this.button1.UseVisualStyleBackColor = false;this.button1.Click += new System.EventHandler(this.button1_Click);this.button1.MouseEnter += new System.EventHandler(this.button1_MouseEnter);this.button1.MouseLeave += new System.EventHandler(this.button1_MouseLeave);// // panel2// this.panel2.Controls.Add(this.roundButton2);this.panel2.Controls.Add(this.label4);this.panel2.Controls.Add(this.label3);this.panel2.Controls.Add(this.pictureBox1);this.panel2.Controls.Add(this.label1);this.panel2.Controls.Add(this.roundButton1);this.panel2.Location = new System.Drawing.Point(9, 46);this.panel2.Name = "panel2";this.panel2.Size = new System.Drawing.Size(864, 524);this.panel2.TabIndex = 5;// // label4// this.label4.AutoSize = true;this.label4.Font = new System.Drawing.Font("新宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label4.Location = new System.Drawing.Point(684, 466);this.label4.Name = "label4";this.label4.Size = new System.Drawing.Size(177, 32);this.label4.TabIndex = 5;this.label4.Text = "工资申请人:\r\n ----小红";// // label3// this.label3.AutoSize = true;this.label3.Font = new System.Drawing.Font("新宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label3.Location = new System.Drawing.Point(268, 391);this.label3.Name = "label3";this.label3.Size = new System.Drawing.Size(406, 21);this.label3.TabIndex = 4;this.label3.Text = "我已经好久没吃过饭了,您就行行好吧!";this.label3.Visible = false;// // pictureBox1// this.pictureBox1.BackgroundImage = global::辞职申请书.Properties.Resources._1;this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;this.pictureBox1.Location = new System.Drawing.Point(211, 69);this.pictureBox1.Name = "pictureBox1";this.pictureBox1.Size = new System.Drawing.Size(500, 319);this.pictureBox1.TabIndex = 2;this.pictureBox1.TabStop = false;// // roundButton2// this.roundButton2.ControlState = 辞职申请书.ControlState.Normal;this.roundButton2.Cursor = System.Windows.Forms.Cursors.Hand;this.roundButton2.FlatAppearance.BorderSize = 0;this.roundButton2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.roundButton2.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.roundButton2.ForeColor = System.Drawing.Color.White;this.roundButton2.HoverColor = System.Drawing.Color.IndianRed;this.roundButton2.Location = new System.Drawing.Point(552, 421);this.roundButton2.Name = "roundButton2";this.roundButton2.NormalColor = System.Drawing.Color.Red;this.roundButton2.PressedColor = System.Drawing.Color.Red;this.roundButton2.Radius = 100;this.roundButton2.Size = new System.Drawing.Size(100, 100);this.roundButton2.TabIndex = 1;this.roundButton2.Text = "丑拒";this.roundButton2.UseVisualStyleBackColor = true;this.roundButton2.Click += new System.EventHandler(this.roundButton2_Click);this.roundButton2.MouseEnter += new System.EventHandler(this.roundButton2_MouseEnter);this.roundButton2.MouseLeave += new System.EventHandler(this.roundButton2_MouseLeave);// // roundButton1// this.roundButton1.ControlState = 辞职申请书.ControlState.Normal;this.roundButton1.Cursor = System.Windows.Forms.Cursors.Hand;this.roundButton1.FlatAppearance.BorderSize = 0;this.roundButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.roundButton1.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.roundButton1.ForeColor = System.Drawing.Color.White;this.roundButton1.HoverColor = System.Drawing.Color.ForestGreen;this.roundButton1.Location = new System.Drawing.Point(297, 418);this.roundButton1.Name = "roundButton1";this.roundButton1.NormalColor = System.Drawing.Color.Blue;this.roundButton1.PressedColor = System.Drawing.Color.Blue;this.roundButton1.Radius = 100;this.roundButton1.Size = new System.Drawing.Size(100, 100);this.roundButton1.TabIndex = 0;this.roundButton1.Text = "准了";this.roundButton1.UseVisualStyleBackColor = true;this.roundButton1.Click += new System.EventHandler(this.roundButton1_Click);this.roundButton1.MouseEnter += new System.EventHandler(this.roundButton1_MouseEnter);this.roundButton1.MouseLeave += new System.EventHandler(this.roundButton1_MouseLeave);// // Form1// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.BackColor = System.Drawing.Color.White;this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;this.ClientSize = new System.Drawing.Size(885, 576);this.Controls.Add(this.panel2);this.Controls.Add(this.panel1);this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));this.Name = "Form1";this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;this.Text = "涨工资申请书";this.TopMost = true;this.Load += new System.EventHandler(this.Form1_Load);this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);this.panel1.ResumeLayout(false);this.panel1.PerformLayout();((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();this.panel2.ResumeLayout(false);this.panel2.PerformLayout();((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();this.ResumeLayout(false);}#endregionprivate RoundButton roundButton1;private RoundButton roundButton2;private System.Windows.Forms.PictureBox pictureBox1;private System.Windows.Forms.Label label1;private System.Windows.Forms.Panel panel1;private System.Windows.Forms.Button button3;private System.Windows.Forms.Button button2;private System.Windows.Forms.Button button1;private System.Windows.Forms.Label label2;private System.Windows.Forms.PictureBox pictureBox2;private System.Windows.Forms.Panel panel2;private System.Windows.Forms.Label label3;private System.Windows.Forms.Label label4;}
}
六、实现过程代码
代码如下:
为了博取领导同志的欢心,本白自定义了个控件,毕竟微软提供的BUTTON是比较丑的,领导看了肯定不满意,原理不难,直接继承Button类然后重写了OnPaint()方法,使用画笔工具重绘控件。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 辞职申请书
{public partial class Form1 : Form{public Form1(){InitializeComponent();}bool agree = false;Point P;private void Form1_Load(object sender, EventArgs e){P = roundButton2.Location;panel2.Location = new Point((this.Width-panel2.Width)/2,(this.Height-panel2.Height + panel1.Height) /2);s = this.Size;Pa();}public void Pa(){panel1.Width = this.Width;button1.Left = panel1.Width - button1.Width;button2.Left = button1.Left - button2.Width;button3.Left = button2.Left - button3.Width;}private void roundButton1_Click(object sender, EventArgs e){pictureBox1.BackgroundImage = Properties.Resources._5;agree = true;roundButton2.Location = P;label3.Visible = false;}private void roundButton2_Click(object sender, EventArgs e){if (agree == false) { }else{pictureBox1.BackgroundImage = Properties.Resources._6;}label3.Visible = false;}private void button1_Click(object sender, EventArgs e){if (agree == false){MessageBox.Show("不涨工资我赖着不走了!哼!~~", "耗子尾汁",MessageBoxButtons.OK,MessageBoxIcon.Error);}else{this.Close();this.Dispose();}}Size s;private void button2_Click(object sender, EventArgs e){if(this.WindowState != System.Windows.Forms.FormWindowState.Maximized)this.WindowState = System.Windows.Forms.FormWindowState.Maximized;else{this.WindowState = System.Windows.Forms.FormWindowState.Normal;this.Size = s;}panel2.Location = new Point((this.Width - panel2.Width) / 2, (this.Height - panel2.Height+panel1.Height) / 2);}private void button3_Click(object sender, EventArgs e){this.WindowState=System.Windows.Forms.FormWindowState.Minimized;}private void roundButton1_MouseEnter(object sender, EventArgs e){}private void roundButton1_MouseLeave(object sender, EventArgs e){if(agree==false)pictureBox1.BackgroundImage = Properties.Resources._1;}private void roundButton2_MouseEnter(object sender, EventArgs e){if (agree == false){Random r = new Random();roundButton2.Location = new Point(r.Next(0, this.Width - roundButton2.Width), r.Next(0, this.Height - roundButton2.Height));if (roundButton2.Left > pictureBox1.Left && roundButton2.Left < pictureBox1.Right - roundButton2.Width){roundButton2.Location = new Point(r.Next(0, this.Width), r.Next(0, this.Height));}}}private void roundButton2_MouseLeave(object sender, EventArgs e){if(agree==false)pictureBox1.BackgroundImage = Properties.Resources._1;else{pictureBox1.BackgroundImage = Properties.Resources._222;}}Point p;private void panel1_MouseDown(object sender, MouseEventArgs e){p = new System.Drawing.Point(e.Location.X, e.Location.Y);}private void panel1_MouseMove(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Left){this.Location = new System.Drawing.Point(this.Location.X + e.X - p.X, this.Location.Y + e.Y - p.Y);}}private void button1_MouseEnter(object sender, EventArgs e){button1.BackColor = Color.Red;button1.ForeColor = Color.White;}private void button1_MouseLeave(object sender, EventArgs e){button1.BackColor = Color.White;button1.ForeColor = Color.Black;}private void Form1_SizeChanged(object sender, EventArgs e){s = this.Size;Pa();}}public enum ControlState { Hover, Normal, Pressed }public class RoundButton : System.Windows.Forms.Button{private int radius;//半径 private Color _baseColor = Color.FromArgb(175, 238, 238);//基颜色private Color _hoverColor = Color.FromArgb(175, 238, 238);//停留颜色private Color _normalColor = Color.FromArgb(255, 99, 71);//初始颜色private Color _pressedColor = Color.FromArgb(255, 130, 71);//单击颜色//圆形按钮的半径属性[CategoryAttribute("布局"), BrowsableAttribute(true), ReadOnlyAttribute(false)]public int Radius{set{radius = value;this.Invalidate();}get{return radius;}}[DefaultValue(typeof(Color), "51, 161, 224")]public Color NormalColor{get{return this._normalColor;}set{this._normalColor = value;this.Invalidate();}}public Color HoverColor{get{return this._hoverColor;}set{this._hoverColor = value;this.Invalidate();}}public Color PressedColor{get{return this._pressedColor;}set{this._pressedColor = value;this.Invalidate();}}public ControlState ControlState{get; set;}protected override void OnMouseEnter(EventArgs e)//鼠标进入时{base.OnMouseEnter(e);ControlState = ControlState.Hover;//正常}protected override void OnMouseLeave(EventArgs e)//鼠标离开{base.OnMouseLeave(e);ControlState = ControlState.Normal;//正常}protected override void OnMouseDown(MouseEventArgs e)//鼠标按下{base.OnMouseDown(e);if (e.Button == MouseButtons.Left && e.Clicks == 1)//鼠标左键且点击次数为1ControlState = ControlState.Pressed;//按下的状态}protected override void OnMouseUp(MouseEventArgs e)//鼠标弹起{base.OnMouseUp(e);if (e.Button == MouseButtons.Left && e.Clicks == 1){if (ClientRectangle.Contains(e.Location))//控件区域包含鼠标的位置ControlState = ControlState.Hover;elseControlState = ControlState.Normal;}}public RoundButton(){Radius = 15;this.ForeColor = Color.White;this.FlatStyle = FlatStyle.Flat;this.FlatAppearance.BorderSize = 0;this.SetStyle(ControlStyles.UserPaint | //控件自行绘制,而不使用操作系统的绘制ControlStyles.AllPaintingInWmPaint | //忽略擦出的消息,减少闪烁。ControlStyles.OptimizedDoubleBuffer |//在缓冲区上绘制,不直接绘制到屏幕上,减少闪烁。ControlStyles.ResizeRedraw | //控件大小发生变化时,重绘。 ControlStyles.SupportsTransparentBackColor, true);//支持透明背景颜色}private Color GetColor(Color colorBase, int a, int r, int g, int b){int a0 = colorBase.A;int r0 = colorBase.R;int g0 = colorBase.G;int b0 = colorBase.B;if (a + a0 > 255) { a = 255; } else { a = Math.Max(a + a0, 0); }if (r + r0 > 255) { r = 255; } else { r = Math.Max(r + r0, 0); }if (g + g0 > 255) { g = 255; } else { g = Math.Max(g + g0, 0); }if (b + b0 > 255) { b = 255; } else { b = Math.Max(b + b0, 0); }return Color.FromArgb(a, r, g, b);}protected override void OnPaint(System.Windows.Forms.PaintEventArgs e){base.OnPaint(e);base.OnPaintBackground(e);e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;e.Graphics.CompositingQuality = CompositingQuality.HighQuality;e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);var path = GetRoundedRectPath(rect, radius);this.Region = new Region(path);Color baseColor = this.NormalColor;switch (ControlState){case ControlState.Hover:baseColor = this.HoverColor;break;case ControlState.Pressed:baseColor = this.PressedColor;break;case ControlState.Normal:baseColor = this.NormalColor;break;default:baseColor = this._normalColor;break;}using (SolidBrush b = new SolidBrush(baseColor)){e.Graphics.FillPath(b, path);System.Drawing.Font fo = new System.Drawing.Font(this.Font.Name, this.Font.Size);Brush brush = new SolidBrush(this.ForeColor);StringFormat gs = new StringFormat();gs.Alignment = StringAlignment.Center; //居中gs.LineAlignment = StringAlignment.Center;//垂直居中e.Graphics.DrawString(this.Text, fo, brush, rect, gs);}}private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius){int diameter = radius;//Point lo = new Point(rect.Location.X + 10, rect.Location.Y + 10);Rectangle arcRect = new Rectangle(rect.Location, new System.Drawing.Size(diameter, diameter));GraphicsPath path = new GraphicsPath();path.AddArc(arcRect, 180, 90);arcRect.X = rect.Right - diameter;path.AddArc(arcRect, 270, 90);arcRect.Y = rect.Bottom - diameter;path.AddArc(arcRect, 0, 90);arcRect.X = rect.Left;path.AddArc(arcRect, 90, 90);path.CloseFigure();return path;}protected override void OnSizeChanged(EventArgs e){base.OnSizeChanged(e);}}
}
七、工程资源文件
以下图片资源依次命名为:1.png、6.png、4.jpg、222.jpg、333.jpg、5.png
ok,点到为止,本猴子要有点码德
这篇关于一个程序员对领导应该有的基本告白的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!