C # Special form making: making arbitrary shape forms

Source: Internet
Author: User

Rationale: Overriding the current form OnPaint method

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();
    }
  }
}

The interface design is attached:

Code generated #region the Windows forms Designer

///<summary>
///Designer supports the desired method-do not
///use the Code Editor to modify the contents of this method.
///</summary>
private void InitializeComponent ()
{
This.label1 = new System.wind oWS. 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 = "Font form";
this. TransparencyKey = System.Drawing.SystemColors.Control;
this. Load + = new System.EventHandler (this. Form1_Load);
this. ResumeLayout (FALSE);
}
#endregion

Article Source: http://www.cnblogs.com/ziyiFly/archive/2008/09/11/1288849.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.