欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net一些很酷很實(shí)用的.Net技巧

 更新時間:2008年08月04日 09:21:05   作者:  
方便使用asp.net編程的朋友,都是一些非常有用的東西




. OOPs 
1. 什么是復(fù)制構(gòu)造函數(shù)

  我們知道構(gòu)造函數(shù)是用來初始化我們要創(chuàng)建實(shí)例的特殊的方法。通常我們要將一個實(shí)例賦值給另外一個變量c#只是將引用賦值給了新的變量實(shí)質(zhì)上是對同一個變量的引用,那么我們怎樣才可以賦值的同時創(chuàng)建一個全新的變量而不只是對實(shí)例引用的賦值呢?我們可以使用復(fù)制構(gòu)造函數(shù)。

我們可以為類創(chuàng)造一個只用一個類型為該類型的參數(shù)的構(gòu)造函數(shù),如:




public Student(Student student)
{
 this.name = student.name;
}

 

使用上面的構(gòu)造函數(shù)我們就可以復(fù)制一份新的實(shí)例值,而非賦值同一引用的實(shí)例了。

class Student
{
     private string name;

     public Student(string name)
     {
         this.name = name;
     }
     public Student(Student student)
     {
         this.name = student.name;
     }

    public string Name 
    {
       get 
       {
              return name; 
       }
       set 
       {
            name = value; 
       }
    }
}

class Final

{

    static void Main()

      {

        Student student = new Student ("A");

        Student NewStudent = new Student (student);

        student.Name = "B";

        System.Console.WriteLine("The new student's name is {0}", NewStudent.Name);

      }

}

 

The new student's name is A.

2.什么是只讀常量

就是靜態(tài)的只讀變量,它通常在靜態(tài)構(gòu)造函數(shù)中賦值。 

class Numbers
{
    public readonly int m;
    public static readonly int n;

    public Numbers (int x)
    {
       m=x;
    }

    static Numbers ()
    {
        n=100;
    }

 } //其中n就是一個只讀的常量,對于該類的所有實(shí)例他只有一種值,而m則根據(jù)實(shí)例不同而不同

 

三.VS.Net IDE

1. 2請看原作

3.如何改變region的顏色

   通過工具 à 選項(xiàng) à 環(huán)境 à 字體和顏色 à 可折疊文本設(shè)置

 

四.WinForm

1.如何使winForm不顯示標(biāo)題欄?

通過設(shè)置form的Text屬性為空字符串,設(shè)置ControlBox屬性為false

form1.Text = string. Empty; 

form1.ControlBox = false;

2.如何使winform的窗體使用XP的風(fēng)格

見原作

3.如何禁止form在工具欄顯示

設(shè)置form的ShowInTaskbar屬性為false即可

4.如何使程序打開默認(rèn)的郵件程序并帶有一些參數(shù)讓用戶開始寫郵件

         1)如果是web程序:

         <a href=”mailto:email@address1.com,email@address2.com?cc=email@address3.com&Subject=Hello&body=Happy New Year”>some text</a>

         2) 對于windows程序,需要使用System.Diagnostics.Process類

Process process = new Process();
process.StartInfo.FileName = "mailto:email@address1.com,email@address2.com?subject=Hello&cc=email@address3.com
&bcc=email@address4.com&body=Happy New Year" ;

process.Start();


5.如何創(chuàng)建類似msn提示窗口

需要獲得通過Screen.GetWorkingArea(this).Width(Height)屬性獲得屏幕的大小,然后使用一個timer根據(jù)時間改變窗口的位置

五.Button控件

1.如何設(shè)置form的默認(rèn)button(即在form上按下回車時觸發(fā)的button)

         可以設(shè)置form的AcceptButton屬性:form1.AcceptButton = button1;

2. 如何設(shè)置form的取消button(即在用戶按下Esc鍵時觸發(fā)的button)

         可以設(shè)置form的CancelButton屬性:form1.CancelButton = buttonC;

3. 如何通過程序觸發(fā)一個button的Click事件

         Button1.PerformClick

 

六.Combo Box

1.如何使用可選字體填充Combo Box

comboBox1.Items.AddRange (FontFamily.Families);

 

七.TextBox

1.如何禁用TextBox的默認(rèn)上下文菜單(右鍵菜單)

textBox1.ContextMenu = new ContextMenu();

2,3 見原作

4.如何在TextBox獲得焦點(diǎn)的時候,將焦點(diǎn)放在textBox文字的最后

textBox1.SelectionStart = textBox1.Text.Length;

相關(guān)文章

最新評論