超碰人人人人人,亚洲AV午夜福利精品一区二区,亚洲欧美综合区丁香五月1区,日韩欧美亚洲系列

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

C#控件的常用操作

admin
2024年12月1日 8:2 本文熱度 720

創(chuàng)建控件

  • 使用new 來創(chuàng)建,比如 TextBox txt=new TextBox();

  • 使用控件對象.Loction= new Point(x,y);設(shè)置控件的初始位置

  • 使用this.Controls.Add(控件對象);將控件對象添加至當前窗體

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CreateControls
{
? ?public partial class Form1 : Form
? ?{
? ? ? ?public Form1()
? ? ? ?{
? ? ? ? ? ?InitializeComponent();
? ? ? ?}

? ? ? ?private void button1_Click(object sender, EventArgs e)
? ? ? ?{
? ? ? ? ? ?TextBox my_txt = new TextBox();
? ? ? ? ? ?my_txt.Location=new Point(25,25);//設(shè)置初始位置
? ? ? ? ? ?this.Controls.Add(my_txt);//將控件添加至當前窗體
? ? ? ?}
? ?}
}

控件的對齊方式

挺簡單,鼠標放上去會告訴你都是什么意思

1.文本控件

  • Label:標簽控件,主要用于顯示不可編輯,通過Text屬性設(shè)置顯示的文本

  • Button:按鈕控件

  • TextBox:文本控件

  • RichTextBox : 富文本控件

Label控件

  • label.Text="";設(shè)置顯示的文本,獲取控件上的值也是通過Text

  • label.Visible=True;//設(shè)置顯示可見,不可見設(shè)置false


Button

  • AcceptButton屬性,當用戶按下Enter鍵,相當于按了Enter

  • 窗體的取消按鈕:用戶按下Esc觸發(fā),this.CancelButton=buuton1;


private void Form1_Load(object sender, EventArgs e)
{
? ? ? ? ? ?this.AcceptButton = button1;
}

RichTextBox

  • Both屬性:文本超出范圍后,行、列的滾動條顯示

  • None:從不顯示滾動條

  • Horizontal:橫向超出范圍,顯示水平滾動條

  • Vertical:縱向超出范圍時,顯示垂直滾動條

  • ForcedHorizontal:當WordWrap設(shè)置為false,顯示水平滾動條,未文本超出范圍,變成灰色

  • ForcedVertical:始終顯示垂直滾動條,未超出范圍,顯示為灰色

  • ForcedBoth:強制顯示水平和垂直方向的滾動條

private void Form1_Load(object sender, EventArgs e)
{
? ?this.AcceptButton = button1;
? ?richTextBox1.Multiline = true;//多行顯示
? ?richTextBox1.ScrollBars = RichTextBoxScrollBars.Vertical;//
? ?//字體設(shè)置
? ?richTextBox1.SelectionFont = new Font("Courier New", 16, FontStyle.Bold);
? ?//字體顏色
? ?richTextBox1.SelectionColor = System.Drawing.Color.Blue;
? ?//段落顯示,每行顯示一個黑點
? ? richTextBox1.SelectionBullet = true;
/ /控件做邊緣與文本間隔8px
? ? ? ? ? ?richTextBox1.SelectionIndent = 8;
? ? ? ? ? ?//右邊設(shè)置12
? ? ? ? ? ?richTextBox1.SelectionRightIndent=12;
}
//打開超鏈接
?private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
? ? ? ?{
? ? ? ? ? ?System.Diagnostics.Process.Start(e.LinkText);
? ? ? ?}

2.選擇控件

  • ComboBox:下拉組合控件

  • CheckBox:復(fù)選框控件

  • RadioButton: 單選按鈕控件

  • NumericupDown:數(shù)值選擇控件

  • ListBox:列表控件

ComboBox

屬性:DropDownStyle

  • Simple:列表值部分可見

  • DropDown: 可以編輯,默認值,單擊右側(cè)箭頭才能顯示列表

  • DropDownList:不可編輯,只顯示

//設(shè)置下拉不可編輯
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
//添加值
comboBox1.Items.Add("C++");
comboBox1.Items.Add("C#");
comboBox1.Items.Add("JS");
comboBox1.Items.Add("Python");

使用SelectAll方法可以選擇可編輯部分的所有文本,但是DropDownStyle必須設(shè)置成DropDown


private void button2_Click(object sender, EventArgs e)
? ? ? ?{
? ? ? ? ? ?//當再次查看下拉表時,可編輯文本中內(nèi)容已經(jīng)被選中
? ? ? ? ? ?comboBox1.SelectAll();
? ? ? ?}

CheckBox

  • CheckState:返回值是Checked(選中) 或Unchecked(未選中)

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
? ?if(checkBox1.CheckState==CheckState.Checked)
? ?{
? ? ? ?MessageBox.Show("復(fù)選框被選中", "");

? ?}
? ?else
? ?{
? ? ? ?MessageBox.Show("復(fù)選框被取消", "");
? ?}
}

RadioButton

  • Checked:true(選中)否則false(未選中)

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
? ?if(radioButton1.Checked==true)
? ?{
? ? ? ?MessageBox.Show("單選按鈕被選中", "");
? ?}
}

NumericUpDown

  • Maximum:設(shè)置上限最大值

  • Minimum:設(shè)置最小值

  • Value:獲得選中的值

private void Form1_Load(object sender, EventArgs e)
{
? ?//設(shè)置數(shù)值控件的選擇范圍
? ?numericUpDown1.Maximum = 100;
? ?numericUpDown1.Minimum=0;
?//數(shù)值后顯示小數(shù)兩位
? ? ?numericUpDown1.DecimalPlaces = 2;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
? ? ?label1.Text = "當前值是:" + numericUpDown1.Value;
}

ListBox

  • Items屬性中的Remove方法刪除項目

  • Items屬性中的Add方法添加值

  • HorizontalScrollbar:設(shè)置水平固定條,true

  • ScrollAlwaysVisible:垂直顯示滾動條,true

SelectionMode枚舉成員

  • MultiExtended:可以多選使用Shift

  • MultiSimple:可以選擇多項

  • None:無法選擇項目

  • One:只能選一個

private void button3_Click(object sender, EventArgs e)
{
? ?if(textBox1.Text!="")
? ?{
? ? ? ?listBox1.Items.Add(textBox1.Text);
? ?}
}

private void button4_Click(object sender, EventArgs e)
{
? ?if(listBox1.SelectedItems.Count!=0)//判斷是否選擇數(shù)據(jù)
? ?{
? ? ? ?listBox1.Items.Remove(listBox1.SelectedItem);
? ?}
}

3. 分組控件

  • Pannel:可用于設(shè)置滾動條, Visiable:true顯示,false隱藏

  • GroupBox:分組控件,Text設(shè)置分組標題

  • TabControl:選項卡控件,Add方法用于添加控件 tabPage1.Controls.Add(btn1),tabControl1.TabPages.Add(),clear清除所有控件


該文章在 2024/12/4 15:23:10 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved