美文网首页
窗体构造函数-自动加载

窗体构造函数-自动加载

作者: Change_6780 | 来源:发表于2020-07-14 17:59 被阅读0次

    1.窗体入口函数 Program.cs

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Threading.Tasks;

    using System.Windows.Forms;

    namespace customerService

    {

        static class Program

        {

            /// <summary>

            /// 应用程序的主入口点。

            /// </summary>

            [STAThread]

            static void Main()

            {

                //用于启动应用程序中可视的样式,如果控件和操作系统支持,那么 控件的绘制就能根据显不风格来实现

                Application.EnableVisualStyles();

                //控件支持 UseCompatibleTextRenderingproperty 属性,该方法将此属 性设置为默认值。

                Application.SetCompatibleTextRenderingDefault(false);

                //启动窗口名

                Application.Run(new TestWeb());

            }

        }

    }

    2.TestWeb.cs

    namespace customerService

    {

        public partial class TestWeb : Form

        {

                //构造函数

                public TestWeb()

                {

                    InitializeComponent();

                }

                //窗体自动加载

                private void Form1_Load(object sender, EventArgs e)

                {

                      1.窗体设置背景色

                        this.BackColor= Color.FromArgb(36, 188, 255);

                        2.启用一个新窗体

                              //创建NewForm窗体实例

                              Form1 newForm = new Form1();

                              //打开NewForm窗体

                              newForm.Show();

                        3.透明

                              this.BackColor = Color.White; this.TransparencyKey = Color.White;

                        4.阴影

                              this.Opacity = 0.5;

                }

              //label背景色渐变

              private void label1_Paint(object sender, PaintEventArgs e)

              {

                  //画个渐变的矩形,大小跟Label1一样大。            

                  e.Graphics.FillRectangle(new LinearGradientBrush(e.ClipRectangle, Color.DarkMagenta, Color.White,            LinearGradientMode.Horizontal)

              , e.ClipRectangle);

                //写字,居中,Font用Label1

                StringFormat stringFormat = new StringFormat();

                stringFormat.Alignment = StringAlignment.Center;

                stringFormat.LineAlignment = StringAlignment.Center;

                Brush brush = new SolidBrush(label1.ForeColor);

                e.Graphics.DrawString(label1.Text, label1.Font, brush, e.ClipRectangle, stringFormat);

            }

        }

    }

    相关文章

      网友评论

          本文标题:窗体构造函数-自动加载

          本文链接:https://www.haomeiwen.com/subject/vpvfhktx.html