特殊窗体设置

13.设置不规则窗体

 private void Form1_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.Size = new Size(130, 120);
            this.Location = new Point(500, 200);
            this.BackgroundImage = Image.FromFile("rose.ico");
            this.TransparencyKey = this.BackColor;
        }


14.设计带分隔栏的窗体

SplitContainer控件

15.在窗体中滚动字幕

  private void button1_Click(object sender, EventArgs e)
        {
            this.timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label1.Left -= -3;
            if (this.label1.Right < 0)
            {
                this.label1.Left = this.Width;
            }
        }
16.设计闪烁的窗体

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.Runtime.InteropServices;
namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        [DllImport("user32")]
        private static extern long FlashWindow(IntPtr handle, bool bInvert);
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.timer1.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.timer1.Enabled = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            FlashWindow(this.Handle,true);
        }
    }
}
注:.NET没有直接提供实现窗体闪烁的类和方法,需要调用Windows的API函数FlashWindow()实现。

在Windows应用程序中使用Windows API函数时,必须引入命名空间System.Runtime.InteropServices。

17.设计动画显示窗体

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.Runtime.InteropServices;
namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public const Int32 AW_HOR_POSITIVE = 0x00000001;
        public const Int32 AW_HOR_NEGATIVE = 0x00000002;
        public const Int32 AW_VER_POSITIVE = 0x00000004;
        public const Int32 AW_VER_NEGATIVE = 0x00000008;
        public const Int32 AW_CENTER = 0x00000010;
        public const Int32 AW_HIDE = 0x00010000;
        public const Int32 AW_ACTIVATE = 0x00020000;
        public const Int32 AW_SLIDE = 0x00040000;
        public const Int32 AW_BLEND = 0x00080000;
        public Form1()
        {
            InitializeComponent();
        }
        [DllImportAttribute("user32.dll")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        private void Form1_Load(object sender, EventArgs e)
        {
            this.pictureBox1.Image = Image.FromFile("123.jpg");
            this.pictureBox1.Dock = DockStyle.Fill;
            AnimateWindow(this.Handle, 300, AW_SLIDE + AW_HOR_NEGATIVE);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            AnimateWindow(this.Handle, 300, AW_SLIDE + AW_HOR_NEGATIVE + AW_HIDE);
        }
    }
}
18.设计运动的窗体

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;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int i = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Top = i;
            i++;
        }
    }
}
19.修改提示框字体及颜色

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;

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
        {
            // 自定义背景
            e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);

            // 绘制标准边界
            e.DrawBorder();
            //封装文本布局信息
            using (StringFormat sf = new StringFormat())
            {
                sf.Alignment = StringAlignment.Center;//设置文本垂直对齐方式
                sf.LineAlignment = StringAlignment.Center;//设置文本水平对齐方式
                using (Font f = new Font("隶书", 16))
                {
                    e.Graphics.DrawString(e.ToolTipText, f,
                        SystemBrushes.ActiveCaptionText, e.Bounds, sf);
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            toolTip1.OwnerDraw = true;
            toolTip1.ShowAlways = true;//总显示提示信息
            toolTip1.SetToolTip(this.button1, "提示文字");//设置提示文字
        }
     
    }
}

20.建立字体形状窗体

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;

namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Bitmap pic;
        private void Form1_Load(object sender, EventArgs e)
        {
            this.ControlBox = false;
            this.FormBorderStyle = FormBorderStyle.None;
            this.TransparencyKey = SystemColors.Control;//关键
            pic = new Bitmap("11.bmp");
            pic.MakeTransparent(Color.Blue);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawImage((Image)pic, new Point(0, 0));//重绘窗体
        }
    }
}

21.设计带帮助键的窗体

 this.MaximizeBox = false;
 this.MinimizeBox = false;
 this.HelpButton = true;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值