程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#特殊窗體制作:制作任意形狀窗體

C#特殊窗體制作:制作任意形狀窗體

編輯:關於C語言
理:重寫當前窗體 OnPaint 方法

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace SpecialSharpWindows
{
  public partial class Form1 : Form
  {
    Bitmap bit;
    public Form1()
    {
      InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
      bit = new Bitmap("heart.bmp");
      bit.MakeTransparent(Color.Blue);
    }
    protected override void OnPaint(PaintEventArgs e)
    {
      e.Graphics.DrawImage((Image)bit, new Point(0, 0));
    }
    private void label1_Click(object sender, EventArgs e)
    {
      this.Close();
    }
  }
}

附界面設計:

#region Windows 窗體設計器生成的代碼

/// <summary>
    /// 設計器支持所需的方法 - 不要
    /// 使用代碼編輯器修改此方法的內容。
    /// </summary>
    private void InitializeComponent()
    {
      this.label1 = new System.Windows.Forms.Label();
      this.SuspendLayout();
      //
      // label1
      //
      this.label1.BackColor = System.Drawing.Color.Transparent;
      this.label1.Location = new System.Drawing.Point(280, 42);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(17, 16);
      this.label1.TabIndex = 0;
      this.label1.Click += new System.EventHandler(this.label1_Click);
      //
      // Form1
      //
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.BackColor = System.Drawing.SystemColors.Control;
      this.ClIEntSize = new System.Drawing.Size(393, 317);
      this.Controls.Add(this.label1);
      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
      this.Name = "Form1";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "字型窗體";
      this.TransparencyKey = System.Drawing.SystemColors.Control;
      this.Load += new System.EventHandler(this.Form1_Load);
      this.ResumeLayout(false);
    }
    #endregion

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved