WinForm 窗體屬性 窗體美化


WinForm是·Net開發平台中對Windows Form的一種稱謂。

Windows窗體的一些重要特點如下:

功能強大:Windows窗體可用於設計窗體和可視控件,以創建豐富的基於Windows的應用程序。

操作方便:新的數據提供程序管理:數據提供程序管理提供易於連接OLEDB和ODBC數據源的數據控件,包括Microsoft SQL Server、Microsoft Access、Jet、DB2以及Oracle等。

使用安全:Windows窗體充分利用公共語言運行庫的安全特性。這就意味着,一切都可以通過Windows窗體來實現,包括在瀏覽器中運行的不可信控件和用戶硬盤上安裝的完全可信的應用程序。

WinForm窗體的常用屬性

1.布局:

AutoScroll - 內容大於課件區域時是否顯示滾動條 true/false 

AutoSize - 是否調整自身大大小以適應起重內容大小 true/false

Location - 左上角的坐標 0,0 (像素)

StartPosition - 第一次出現時的位置 CenterScreen 居中顯示
MaxximumSize - 窗口可調整到的最大大小
MinimunSize -窗口可調整到的最小大小
padding - 內部間距0,0,0,0 左上右下
Size - 控件大小300,300(以像素為單位)
WindowState - 確定初始可是狀態 Minimized 最小化 Maximized 最大化

2.窗口樣式:
ControlBox -確定是否有系統菜單邊框 true/false
Icon - 窗體圖標,最小化時顯示 ico 格式

MaximizeBox - 確定右上角是否有最大化框
MinimizeBox - 確定右上角是否是最小化框
HelpButton - 標題欄上的幫助按鈕
MaximizeBox與 MinimizeBox 同時為False HelpButton True是顯示 
Opacity -透明度
ShowIcon - 窗體標題欄中是否顯示圖標
ShowInTaskbar - Windows 任務欄中是否顯示窗體
TopMost - 是否顯示在此屬性威懾住為true的所有窗體之上
TransparencyKey - 窗體上顯示透明的顏色

3.設計:
Name - 對象中用來識別對象的名稱

4.數據:
Tag -與對象關聯的用戶定義數據

5.外觀:
BackgroundImage - 背景圖片
BackgroundImagelayout - 背景圖片的布局
BackColor -背景顏色
Cursor - 顯示的鼠標樣式
FormBorderStyle - 邊框的和標題欄的樣式
Text 窗體的文本
6.雜項:
AcceptButton -設置了此按鈕,用戶按Enter相當於“單擊”。
CancelButton - 設置了此按鈕,用戶按Eec相當於“單擊”

窗體美化

一.制作一個無邊框窗體

屬性FormBorderStyle 設置為NONE

二.控制按鈕如何制作

 

 1  //觸發事件改變它的背景圖片 關閉按鈕為例
 2         private void pictureBox1_Click(object sender, EventArgs e)//點擊事件
 3         {
 4             this.Close();
 5         }
 6         private void pictureBox1_MouseEnter(object sender, EventArgs e)//鼠標進入事件
 7         {
 8             pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + "\\..\\..\\images\\btn_close_highlight.png");
 9         }
10 
11         private void pictureBox1_MouseLeave(object sender, EventArgs e)//鼠標離開時事件
12         {
13             pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + "\\..\\..\\images\\btn_close_disable.png");
14         }
15 
16         private void pictureBox1_MouseDown(object sender, MouseEventArgs e)//鼠標按下事件
17         {
18             pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + "\\..\\..\\images\\btn_close_down.png");
19

三.如何讓窗體動起來

 

 1 //窗體移動API
 2 [DllImport("user32.dll")]
 3 public static extern bool ReleaseCapture();
 4 [DllImport("user32.dll")]
 5 public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
 6 public const int WM_SYSCOMMAND = 0x0112;
 7 public const int SC_MOVE = 0xF010;
 8 public const int HTCAPTION = 0x0002;
 9 [DllImport("user32")]
10 private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
11 private const int WM_SETREDRAW = 0xB;
12 
13 
14 
15 private void Form1_MouseDown(object sender, MouseEventArgs e)
16 {
17     if (this.WindowState == FormWindowState.Normal)
18     {
19         ReleaseCapture();
20         SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
21     }
22 }

四.如何讓窗體有陰影 

 1 using System.Runtime.InteropServices;//引用命名空間
 2 
 3 
 4         //代碼如下
 5          private const int CS_DropSHADOW = 0x20000;
 6          private const int GCL_STYLE = (-26);
 7  
 8         [DllImport("user32.dll", CharSet = CharSet.Auto)]
 9          public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
10         [DllImport("user32.dll", CharSet = CharSet.Auto)]
11          public static extern int GetClassLong(IntPtr hwnd, int nIndex);
12 
13         public Form1()
14         {
15 
16 
17             InitializeComponent();
18             SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
19         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM