用C# Builder制作不规则窗体

2016-02-19 16:56 1 1 收藏

下面是个超简单的用C# Builder制作不规则窗体教程,图老师小编精心挑选推荐,大家行行好,多给几个赞吧,小编吐血跪求~

【 tulaoshi.com - 编程语言 】

  作不规则窗体涉及到API的调用和大量的编程,是件很复杂的事情。下面我们可以使用Borland C# Builder轻松的实现一个不规则窗体,以下面用一个示例来讲述其制作过程。

  一.准备不规则窗体位图

  二.窗体的设置

  三.代码的完成

  一.准备不规则窗体位图

  为了方便起见,我们随便找几个别的软件用的Skin。

  这里使用金山影霸 2003的安装目录下的skinsoceanKingDVD_Disable.BMP

  当然完全可以使用画图工具,制作一个有形状的位图,背景使用一种特别的颜色,如白色。这个颜色会在后面用得上。

  [ 相关贴图 ]

  二.窗体的设置

  1.新建C# Application

  [ 相关贴图 ]

  2.选中新建的窗体,设置其相应属性:

  (1).将 FormBorderStyle 属性设置为 None。

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  (2).将窗体的 BackgroundImage 属性设置为先前面的位图文件。

  (3).将 TransparencyKey 属性设置为位图文件的背景色,本例中为白色。(此属性告诉应用程序窗体中的哪些部分需要设置为透明。 )

  (4).加一个picturebox1,就是一关闭位图,点击时关闭应用程序。

  (5).加一个contextMenu1,添加一菜单项退出,将winform的contextMenu设为contextMenu1。

  按F9运行你的程序,就可以看到你的不规则窗体了。

  [ 相关贴图 ]

  三.实现代码

  前面做的窗口还不能移动。加入下面的代码使其能移动起来,帖出完整的示例代码:

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  

using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace SForm{/// summary/// Summary description for WinForm./// /summarypublic class WinForm : System.Windows.Forms.Form{/// summary/// Required designer variable./// /summaryprivate System.ComponentModel.Container components = null;private System.Windows.Forms.ContextMenu contextMenu1;private System.Windows.Forms.MenuItem menuItem1;private Point mouseOffset; //记录鼠标指针的坐标private bool isMouseDown = false;private System.Windows.Forms.PictureBox pictureBox1; //记录鼠标按键是否按下public WinForm(){//// Required for Windows Form Designer support//InitializeComponent();//// TODO: Add any constructor code after InitializeComponent call//}/// summary/// Clean up any resources being used./// /summaryprotected override void Dispose (bool disposing){if (disposing){if (components != null){components.Dispose();}}base.Dispose(disposing);}#region Windows Form Designer generated code/// summary/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// /summaryprivate void InitializeComponent(){System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WinForm));this.contextMenu1 = new System.Windows.Forms.ContextMenu();this.menuItem1 = new System.Windows.Forms.MenuItem();this.pictureBox1 = new System.Windows.Forms.PictureBox();this.SuspendLayout();//// contextMenu1//this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {this.menuItem1});//// menuItem1//this.menuItem1.Index = 0;this.menuItem1.Text = "退出";this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);//// pictureBox1//this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));this.pictureBox1.Location = new System.Drawing.Point(290, 8);this.pictureBox1.Name = "pictureBox1";this.pictureBox1.Size = new System.Drawing.Size(14, 13);this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;this.pictureBox1.TabIndex = 0;this.pictureBox1.TabStop = false;this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);//// WinForm//this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));this.ClientSize = new System.Drawing.Size(365, 235);this.ContextMenu = this.contextMenu1;this.Controls.Add(this.pictureBox1);this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;this.MaximizeBox = false;this.MinimizeBox = false;this.Name = "WinForm";this.Text = "WinForm";this.TransparencyKey = System.Drawing.Color.White;this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.WinForm_MouseDown);this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.WinForm_MouseUp);this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.WinForm_MouseMove);this.ResumeLayout(false);}#endregion/// summary/// The main entry point for the application./// /summary[STAThread]static void Main(){Application.Run(new WinForm());}private void menuItem1_Click(object sender, System.EventArgs e){this.Close();}private void WinForm_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e){if (isMouseDown){Point mousePos = Control.MousePosition;mousePos.Offset(mouseOffset.X, mouseOffset.Y);Location = mousePos;}}private void WinForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e){int xOffset;int yOffset;if (e.Button == MouseButtons.Left){xOffset = -e.X - SystemInformation.FrameBorderSize.Width;yOffset = -e.Y - SystemInformation.CaptionHeight -SystemInformation.FrameBorderSize.Height;mouseOffset = new Point(xOffset, yOffset);isMouseDown = true;}}private void WinForm_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e){// 修改鼠标状态isMouseDown的值// 确保只有鼠标左键按下并移动时,才移动窗体if (e.Button == MouseButtons.Left){isMouseDown = false;}}private void pictureBox1_Click(object sender, System.EventArgs e){this.Close();}}} 

  注:如果监视器的颜色深度设置大于 24 位,TransparencyKey 设置成白色,窗体的非透明部分还是会显示出来,不知道为什么。

来源:https://www.tulaoshi.com/n/20160219/1613596.html

延伸阅读
PSS ID Number: Q320687 当你设计一个应用程序时,或许你希望用户能够通过客户区来拖动窗体,比如:当窗体没有标题栏或创建的是不规则的窗体时,就只有通过客户区来拖动窗体了。 一个发生在我们身边很好的例子就是Microsoft Windows Media Player。Media Player有项功能是根据用户的爱好可以随意换掉外观(换肤),这个时候标题栏就隐藏了,但...
我们已经了解了Visual Basic或者Delphi等语言是如何来实现对屏幕图象捕获的。那么对于C#来说,是如何实现这种功能的?本文就来探讨一下这个问题。 一. 程序设计开发及运行环境: (1).微软视窗2000服务器版 (2)..Net FrameWork SDK Beta 2 二. 程序设计的关键步骤以及具体的实现方法: (1).首先要创建一...
负责任的说:这将是你吃过最好吃的饼干! 1.熟杏仁打磨成粉,也可以用其他坚果粉代替; 2.蛋白加糖到到干性发泡,就是成为固体状。 3.混合1+2,装进裱花袋或保险模,在铺锡纸的烤盘上挤成圆圈或其他形状。 4.烤箱预热,150度15分钟。 真的相当好吃,不试不知道哦! 猫爪饼干 1.黄油软化后加入糖,打到体积变大颜色变淡,加盐、低粉...
在本文,我将介绍如何使用C# Builder导入一个Web服务,并且将它变成一个井字游戏客户端。源代码(也可以使用.NET SDK下的C#命令行编译程序编译)可在BDS\1.0\Examples\C#\Web Services\Tic Tac Toe目录下获得,也可以在CodeCentral下获得,但是放心启动C# Builder然后跟着我输入代码,看看我是如何创建并且构建这个工程的。 C# Builde...
标签: 鸡蛋 蛋黄
岩石饼干 1.黄油在室温下软化到20度左右,加入糖粉 2.低筋面粉加泡打粉混合过筛 3.黄油先用手动打蛋器搅拌均匀,然后再打至膨松 4.加入室温下的蛋黄一个,打至混合均匀 5.黄油中倒入过筛好的低筋面粉 6.杏仁切成碎粒 7.低筋面粉和黄油混合好后,加入杏仁粒 8.混合均匀后,分成20个份量相等的小饼干坯,分布在铺有油纸的烤盘上,烤箱...

经验教程

54

收藏

23
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部