日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c#窗体

發布時間:2023/12/18 C# 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c#窗体 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

窗體的設置:
對于窗體,c#有個用于創建窗體的命名空間:System.Windows.Forms。想要創建一個窗體只需new 一個Form實例就行了。

1 using System; 2 using System.Windows.Forms; 3 namespace MyFirstWin { 4   class First : Form { 5     static void Main() { 6       Application.Run(new First()); 7     } 8   } 9 }

但這只是一個空空的窗體,因此需要一些設置。

Width: 窗體的寬

Height: 窗體的高

Size: 窗體的大小

BackColor: 窗體的背景色

ForeColor: 窗體的前景色

FormBorderStyle: 窗體的邊框樣式

StartPosition: 窗體開始的位置

MaximizeBox: 設置是否可以最大化

MinimizeBox: 設置是否可以最小化

ControlBox: 設置是否可以操控窗體

Opacity: 窗體的透明度

Name: 窗體的名稱

Text: 窗體的標題

Location: 設置窗體的位置

BackgroundImage:?設置背景圖片

TabIndex:?獲取或設置控件在其容器內的 Tab 鍵順序

WindowState:?獲取或設置一個值,該值指示窗體是最小化、最大化還是正常


FormBorderStyle的值分別有:

  Fixed3D: 三維邊框

  FixedDialog: 對話框粗邊框

  FixedSingle: 固定的單行邊框

  FixedToolWindow: 固定的工具欄不可調整邊框

  Sizable: 可調整邊框

  SizableTollWindow: 可調整的工具欄邊框

  None: 沒有邊框


StartPosition的值設置是枚舉一個FormStartPosition來取值:

  CenterScreen: 相對于當前窗口中居中

  CenterParent: 居中父窗體

  Manual: 窗體的位置由Location設置

  WindowsDefaultBounds: 位置為Window 默認位置,其邊界也由Window決定

  WindowsDefaultLocation: 位置為window 默認位置,其尺寸在窗體大小中設置。

?

1 using System; 2 using System.Drawing; 3 using System.Windows.Forms; 4 5 namespace Program { 6 class Form1 : Form { 7 static void Main() { 8 Form1 f = new Form1(); 9 10 f.Name = "Form1"; 11 // 設置標題 12 f.Text = "第二個窗體"; 13 // 寬高 14 f.Width = 500; 15 f.Height = 300; 16 // 背景顏色 17 f.BackColor = Color.FromArgb(0, 255, 255); 18 // 前景色 19 f.ForeColor = Color.Black; 20 // 邊框樣式 21 f.FormBorderStyle = FormBorderStyle.Fixed3D; 22 // 窗體位置 23 f.StartPosition = FormStartPosition.WindowsDefaultLocation; 24 // 透明度 25 f.Opacity = .8; 26 27 // 顯示窗體 28 f.ShowDialog(); 29 } 30 } 31 }

?

為窗體設置MaximizzeBox、MinimizeBox、ControlBox?設置窗體的最大化、最小化、關閉

  不允許最小化:

  

?  

1     static void Main() { 2 Form1 f = new Form1(); 3 f.Width = 500; 4 f.Height = 300; 5 f.BackColor = Color.FromArgb(0, 255, 255); 6 f.Text = "禁止最小化"; 7 f.MinimizeBox = false; 8 f.ShowDialog(); 9 }

?

  不允許最大化:

  

  

1 static void Main() { 2 Form1 f = new Form1(); 3 f.Width = 500; 4 f.Height = 300; 5 f.BackColor = Color.FromArgb(0, 255, 255); 6 f.Text = "禁止最大化"; 7 f.MaximizeBox = false; 8 f.ShowDialog(); 9 }

?

? 不允許對窗體的操作:

?

?  

1 static void Main() { 2 Form1 f = new Form1(); 3 f.Width = 500; 4 f.Height = 300; 5 f.BackColor = Color.FromArgb(0, 255, 255); 6 f.Text = "禁止對窗體的操作"; 7 f.ControlBox = false; 8 f.ShowDialog(); 9 }

?

  為窗體設置背景圖片:

    

1 static void Main() { 2 Form1 f = new Form1(); 3 4 f.Width = 500; 5 f.Height = 300; 6 f.Text = "我有背景圖片"; 7 f.BackgroundImage = Image.FromFile(@"E:\server\Apache24\htdocs\www\tianmao\images\hc-1.jpg"); 8 f.ShowDialog(); 9 }

?

?對窗體位置的操作:

?  為StartPosition設置CenterScreen

    

  

1 static void Main() { 2 Form1 f = new Form1(); 3 4 f.Width = 500; 5 f.Height = 300; 6 f.Text = "StartPosition-CenterScreen"; 7 f.StartPosition = FormStartPosition.CenterScreen; 8 f.ShowDialog(); 9 }

?

  為StartPosition設置CenterParent

  

  

1 static void Main() { 2 Form1 f = new Form1(); 3 4 f.Width = 500; 5 f.Height = 300; 6 f.Text = "StartPosition-CenterParent"; 7 f.StartPosition = FormStartPosition.CenterParent; 8 f.ShowDialog(); 9 }

  

  為StartPosition設置WindowsDefaultBounds

  

1 static void Main() { 2 Form1 f = new Form1(); 3 4 f.Width = 500; 5 f.Height = 300; 6 f.Text = "StartPosition-WindowsDefaultBounds"; 7 f.StartPosition = FormStartPosition.WindowsDefaultBounds; 8 f.ShowDialog(); 9 }

?

  為StartPosition設置WindowsDefaultLocation

  

1 static void Main() { 2 Form1 f = new Form1(); 3 4 f.Width = 500; 5 f.Height = 300; 6 f.Text = "StartPosition-WindowsDefaultLocation"; 7 f.StartPosition = FormStartPosition.WindowsDefaultLocation; 8 f.ShowDialog(); 9 }

?

?  為StartPosition設置Manual,?并定位到100 * 100處

  

1 static void Main() { 2 Form1 f = new Form1(); 3 4 f.Width = 500; 5 f.Height = 300; 6 f.Location = new Point(100, 100); 7 f.Text = "StartPosition-Nanual"; 8 f.StartPosition = FormStartPosition.Manual; 9 f.ShowDialog(); 10 }

?

  更多的設置可以參考:?https://msdn.microsoft.com/zh-cn/library/system.windows.forms.form(v=vs.110).aspx

轉載于:https://www.cnblogs.com/LiQingsong/p/8573739.html

總結

以上是生活随笔為你收集整理的c#窗体的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。