
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
namespace CSystem
{
public partial class frmStart : Form
{ 
private clsFun.DrawOnPint DrawPint = new clsFun.DrawOnPint();
private clsFun.GraphicsPathArc PathArc = new clsFun.GraphicsPathArc();
private clsFun.CursorType MouseSize = new clsFun.CursorType(0, 0);
private Point mouseOffset;
private Boolean isMouseDown = false;
////任务栏右键菜单
//----------------------------------------------------------------------------------------------------
[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
void NoneBorder()
{
int WS_SYSMENU = 0x00080000; // 系统菜单
int WS_MINIMIZEBOX = 0x20000; // 最大最小化按钮 0x40000禁止返原按钮,0x10000禁止最小化按钮
int windowLong = (GetWindowLong(new HandleRef(this, this.Handle), -16));
SetWindowLong(new HandleRef(this, this.Handle), -16, windowLong | WS_SYSMENU | WS_MINIMIZEBOX);
}
//------------------------------------------------------------------------------------------------------

/// <summary>
/// 构造
/// </summary>
public frmStart()
{
InitializeComponent();
SetWindowsForm();
}
private void SetWindowsForm()
{
////设置窗体标题和位置大小
base.FormBorderStyle = FormBorderStyle.None;
base.BackColor = Color.FromArgb(236, 246, 249);
base.Text = "Imitation msn";//Center System
base.Width = 350;
base.Height = 660;
base.AutoScroll = false;
MouseSize.Action = null;
clsFun.DrawOnPint.UFontType mFontType = new clsFun.DrawOnPint.UFontType();
mFontType.mFont = new Font("Arial", 10, FontStyle.Bold);//Arial, Arial Black, Arial Narrow
mFontType.mColor = Color.FromArgb(255, 255, 255);
mFontType.mTitle = "IIM";
mFontType.mPen = new Pen(Color.FromArgb(112, 112, 112), 1);
DrawPint.SetFontType(mFontType);
DrawPint.SetDrawPint(this.Width, this.Height);
//绘制圆弧
PathArc.SetArcParameter(11, DrawPint.Height, DrawPint.Width);
this.Region = PathArc.GetGraphicArcValue();
//事件
this.Resize += new EventHandler(frmStart_Resize);
//
CreateComponent();
NoneBorder();
}
private void CreateComponent()
{
UButton[] mBut = new UButton[5];
for (int i = 0; i < mBut.Length; i++)
{
mBut[i] = new UButton();
mBut[i].Tag = i;
mBut[i].Text = i.ToString();
mBut[i].Click += new EventHandler(frmStart_Max_Min_Close_Click);
this.Controls.Add(mBut[i]);
}
mBut[0].SetBmp(Properties.Resources.SysButtonMin,
Properties.Resources.SysButtonMinHover,
Properties.Resources.SysButtonMinClick,
Properties.Resources.SysButtonMin.Width,
Properties.Resources.SysButtonMin.Height);
mBut[1].SetBmp(Properties.Resources.SysButtonMax,
Properties.Resources.SysButtonMaxHover,
Properties.Resources.SysButtonMaxClick,
Properties.Resources.SysButtonMax.Width,
Properties.Resources.SysButtonMax.Height);
mBut[2].SetBmp(Properties.Resources.SysButtonClose,
Properties.Resources.SysButtonCloseHover,
Properties.Resources.SysButtonCloseClick,
Properties.Resources.SysButtonClose.Width,
Properties.Resources.SysButtonClose.Height);
mBut[3].SetBmp(Properties.Resources.log,
Properties.Resources.log,
Properties.Resources.log,
Properties.Resources.log.Width,
Properties.Resources.log.Height);
mBut[4].SetBmp(Properties.Resources.Syslogin,
Properties.Resources.SysloginHover,
Properties.Resources.SysloginClick,
Properties.Resources.Syslogin.Width,
Properties.Resources.Syslogin.Height);
ComboBox[] mCB = new ComboBox[1];
for (int i = 0; i < mCB.Length; i++)
{
mCB[i] = new ComboBox();
mCB[i].Tag = i;
mCB[i].BackColor = Color.FromArgb(236, 246, 249);
mCB[i].FlatStyle = FlatStyle.Popup;
mCB[i].Text = "nicepaintoem@163.com";
this.Controls.Add(mCB[i]);
}
Label[] mLab = new Label[7];
for (int i = 0; i < mLab.Length; i++)
{
mLab[i] = new Label();
mLab[i].Tag = i;
mLab[i].AutoSize = true;
if (i <= 2) { mLab[i].ForeColor = Color.FromArgb(69, 69, 69); }
else
{ mLab[i].ForeColor = Color.FromArgb(0, 136, 228); }
this.Controls.Add(mLab[i]);
}
mLab[0].Text = "电子邮件地址(&E):";
mLab[1].Text = "密码(&W):";
mLab[2].Text = "登陆状态:";
mLab[3].Text = "说明:模仿MSN界面制作";
mLab[4].Text = "开发平台:Microsoft Visual Studio .net C#";
mLab[5].Text = "模仿者:小李";
mLab[6].Text = "MSN:nicepaintoem@hotmail.com"; 
UTextBox[] mTebox = new UTextBox[1];
for (int i = 0; i < mTebox.Length; i++)
{
mTebox[i] = new UTextBox();
mTebox[i].Tag = i;
mTebox[i].BackColor = Color.FromArgb(236, 246, 249);
mTebox[i].ForeColor = Color.FromArgb(60, 198, 221);
mTebox[i].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(mTebox[i]);
}
mTebox[0].PasswordChar = (char)'*';
mTebox[0].Text = "123456789";
UCheckBox[] mRadioButt = new UCheckBox[3];
for (int i = 0; i < mRadioButt.Length; i++)
{
mRadioButt[i] = new UCheckBox();
mRadioButt[i].Tag = i;
mRadioButt[i].BackColor = Color.FromArgb(236, 246, 249);
mRadioButt[i].ForeColor = Color.FromArgb(69, 69, 69);
mRadioButt[i].AutoSize = true;
mRadioButt[i].FlatStyle = FlatStyle.Flat;
mRadioButt[i].SetBmp(Properties.Resources.Checkbox_CheckState_false,
Properties.Resources.Checkbox_CheckState_false_Hover,
Properties.Resources.Checkbox_CheckState_false_Click,
Properties.Resources.Checkbox_CheckState_true,
Properties.Resources.Checkbox_CheckState_true_Hover,
Properties.Resources.Checkbox_CheckState_true_Click,
Properties.Resources.Checkbox_CheckState_true.Width,
Properties.Resources.Checkbox_CheckState_true.Height);
this.Controls.Add(mRadioButt[i]);
}
mRadioButt[0].Text = "保存我的信息(&B)";
mRadioButt[0].Checked = true;
mRadioButt[1].Text = "记住我的密码(&R)";
mRadioButt[2].Text = "自动为我登陆(&N)";


}
private void frmStart_Max_Min_Close_Click(object sender, EventArgs e)
{
switch ((int)((UButton)sender).Tag)
{
case 0:
base.WindowState = FormWindowState.Minimized;
break;
case 1:
if (base.WindowState == FormWindowState.Normal)
{
this.WindowState = FormWindowState.Maximized;
DrawPint.SetDrawPint(this.Width, this.Height);
PathArc.SetArcParameter(11, DrawPint.Height, DrawPint.Width);
this.Region = PathArc.GetGraphicArcValue();
this.Invalidate();
}
else
{
this.WindowState = FormWindowState.Normal;
DrawPint.SetDrawPint(this.Width, this.Height);
PathArc.SetArcParameter(11, DrawPint.Height, DrawPint.Width);
this.Region = PathArc.GetGraphicArcValue();
this.Invalidate();
}
break;
case 2:
this.Close();
break;
default:
break;
}
}
private void FindingComponent(Control pCTL, ComboBox[] pCB,UButton[] pBut,Label[] pLab,
UTextBox[] pTebox, UCheckBox[] pRadioButt)
{
foreach (Control ctl in pCTL.Controls)
{
if (ctl is ComboBox)
{
int i = int.Parse(Convert.ToString(ctl.Tag));
pCB[i] = (ComboBox)ctl;
}
if (ctl is UButton)
{
int i = int.Parse(Convert.ToString(ctl.Tag));
pBut[i] = (UButton)ctl;
}
if (ctl is Label)
{
int i = int.Parse(Convert.ToString(ctl.Tag));
pLab[i] = (Label)ctl;
}
if (ctl is UTextBox)
{
int i = int.Parse(Convert.ToString(ctl.Tag));
pTebox[i] = (UTextBox)ctl;
}
if (ctl is UCheckBox)
{
int i = int.Parse(Convert.ToString(ctl.Tag));
pRadioButt[i] = (UCheckBox)ctl;
}
if (ctl.Controls.Count > 0)
{
FindingComponent(ctl, pCB, pBut, pLab, pTebox, pRadioButt);
}
}
}
private void frmStart_Resize(object sender, EventArgs e)
{
//最小化,则不出理
if (this.WindowState == FormWindowState.Minimized)
{
return;
}
//正常模式,则限制其大小
if (this.WindowState == FormWindowState.Normal)
{
//窗口的宽度和高度750, 450
if (this.Width < 250) this.Width = 250;
if (this.Height < 400) this.Height = 400;
}
if (this.Width < 1000 || this.Height < 600)
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width - 10,
Screen.PrimaryScreen.Bounds.Top + 30);
UTextBox[] fTebox = new UTextBox[1];
ComboBox[] fCB = new ComboBox[1];
UButton[] fBut = new UButton[5];
Label[] fLab = new Label[7];
UCheckBox[] fRadioButt = new UCheckBox[3];
FindingComponent(this, fCB, fBut, fLab, fTebox, fRadioButt);
fBut[0].Location = new Point(this.Width - (fBut[0].Width + fBut[1].Width + fBut[2].Width + 10), 0);
fBut[1].Location = new Point(fBut[0].Right, 0);
fBut[2].Location = new Point(fBut[1].Right, 0);
fBut[3].Location = new Point(this.Width / 2 - Properties.Resources.log.Width / 2,
Properties.Resources.Topleft.Height + (Properties.Resources.log.Height / 2));
fLab[0].Location = new Point(fBut[3].Left - fBut[3].Width / 2, fBut[3].Bottom + 30);
fLab[0].AutoSize = true;
fCB[0].Location = new Point(fLab[0].Left, fLab[0].Bottom + 2);
fCB[0].Size = new Size(fBut[3].Width * 2, fCB[0].Height);
fLab[1].Location = new Point(fLab[0].Left, fCB[0].Bottom + 10);
fLab[1].AutoSize = true;
fTebox[0].Location = new Point(fLab[1].Left, fLab[1].Bottom + 2);
fTebox[0].Size = new Size(fCB[0].Width, fTebox[0].Height);
fLab[2].Location = new Point(fTebox[0].Left, fTebox[0].Bottom + 10);
//
fRadioButt[0].Location = new Point(fLab[2].Left, fLab[2].Bottom + 15);
fRadioButt[1].Location = new Point(fRadioButt[0].Left, fRadioButt[0].Bottom + 10);
fRadioButt[2].Location = new Point(fRadioButt[1].Left, fRadioButt[1].Bottom + 10);
fBut[4].Location = new Point(this.Width / 2 - fBut[4].Width / 2, fRadioButt[2].Bottom + 30);
//
fLab[3].Location = new Point(fRadioButt[2].Left, this.Height - 100);
fLab[4].Location = new Point(fRadioButt[2].Left, fLab[3].Bottom + 5);
fLab[5].Location = new Point(fRadioButt[2].Left, fLab[4].Bottom + 5);
fLab[6].Location = new Point(fRadioButt[2].Left, fLab[5].Bottom + 5);
}

重载事件

}
}
这是一个使用C#编写的模仿MSN界面的程序,实现了窗口无边框、圆角效果,包含最大化、最小化和关闭按钮。程序中包含了自定义控件如按钮、组合框、标签、文本框等,并且对窗口进行了布局调整和鼠标事件处理,允许用户进行窗口拖动和大小调整操作。

8683

被折叠的 条评论
为什么被折叠?



