C#手記(一)

來源:互聯網
上載者:User

時間********************************************
 
            //擷取目前時間
            //DateTime NowTime = DateTime.Now;          
            DateTime NowTime = new DateTime(2011,2,5,11,32,18);
            //擷取年、月、日、星期、時間
            MessageBox.Show("Year: " + NowTime.Year + "/n" +
                            "Month: " + NowTime.Month + "/n" +
                            "Day: " + NowTime.Day + "/n" +
                            "Date: " + NowTime.Date + "/n" +
                            "DayOfWeek: " + (int)NowTime.DayOfWeek + "/n" +
                            "DayOfWeek: " + NowTime.DayOfWeek + "/n" +
                            NowTime.ToString("yyyy年mm月dd日hh時mm分ss秒")
                           );

所有的基礎資料型別 (Elementary Data Type)都可以用ToString()方法轉換為字串.

TEXTBOX********************************************

            //可以顯示多行
            ttbxTemp.Multiline = true;
            //捲軸
            ttbxTemp.ScrollBars = ScrollBars.Both;

            //當前內容清空
            ttbxTemp.Clear();
           
            //當前內容複寫到剪貼簿
            ttbxTemp.Copy();

            //剪貼簿複製到當前內容
            ttbxTemp.Paste();

            //當前內容剪貼到剪貼簿
            ttbxTemp.Cut();

 

ArrayList********************************************
  //引用單元
  using System.Collections;

  //長度
  arltMastField.Count;

TableLayoutPanel控制項********************************************
  //添加行(TableLayoutPanel的AutoSize屬性為True,否則需要指定Height)
  tlpMain.RowCount = tlpMain.RowCount + 1;
 
  //設定行
            const int pnlHeight = 25;

            tlpMain.RowCount = RowCount;

            tlpMain.Height = tlpMain.RowCount * pnlHeight;

            for (int i = 0; i < tlpMain.RowCount; i++)
            {
                tlpMain.RowStyles.Add(new RowStyle(SizeType.Absolute, pnlHeight));
                tlpMain.RowStyles[i].Height = pnlHeight;
            }

  //設定列
            float pnlWidth;

            tlpMain.ColumnCount = ColCount;

            pnlWidth = (tlpMain.Width / tlpMain.ColumnCount);

            for (int i = 0; i < tlpMain.ColumnCount; i++)
            {
                tlpMain.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, pnlWidth));
                tlpMain.ColumnStyles[i].Width = pnlWidth;

            }

  //添加控制項(自動將控制項放置到一個空Cell)
  tlpMain.Controls.Add(ttbxMast);

加入OracleClient命名空間********************************************
1.添加引用
右擊你的項目名稱-->[Add Reference]-->在.NET下找到“System.Data.OracleClient”-->[確定]
2.引用命名空間
在代碼中添加“using System.Data.OracleClient”

Oracle資料庫********************************************

1.讀取欄位
             try
            {

                OracleDataReader mastTableReader;
                DataBaseManage mastTable = new DataBaseManage(ttbxConnDataBaseStr.Text);

                mastTableReader = mastTable.ExecuteReader(sqlText);
                //第一種方式
                while (mastTableReader.Read())
                {
                    MessageBox.Show(mastTableReader["column_name"].ToString() + "; " + mastTableReader["comments"].ToString());
                }

                mastTableReader.Close();

                //關閉資料庫
                mastTable.CloseDataBase();

            }
            catch(Exception mE) {
                throw mE;
            }

自訂結構********************************************
    //定義主表類型結構體
    public struct struMastField
    {
        public String FieldName; //欄位名
        public String Caption; //標題
        public String ControlType; //控制項類型
        public Boolean Visible; //是否顯示
    }

字串********************************************
  ToLower() //轉小寫

DataGridView********************************************
    ColumnHeaderDefault->Alignment屬性: 標題文字位置
    FefaultCellStyle屬性: 調整網格屬性 
    EnableHeadersVisualStyles屬性:是否起用自訂的標題屬性
    RowHeadersVisible屬性: 是否顯示第1列
    RowDefaultCellStyle->BackColor屬性: 行背景顏色
 

    dgView[indexCol, indexRowT].Value = dgView[indexCol, indexRowS].Value //賦值
    dgView.CurrentCell //當前網格
    dgView.Rows.Add(); //添加行
    dgView.Rows.Insert(rowIndex, count); //插入行
   
    //設定標題高
    dgView.ColumnHeadersHeightSizeMode = EnableResizing;
    dgView.ColumnHeadersHeight = 28;
    
    CellBorderStyle屬性: //網格邊框類型

Color********************************************
    lblTemp.BackColor = System.Drawing.Color.IndianRed;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.