two
. OOPs
1. What is a copy constructor
We know that constructors are special methods used to initialize the instance we want to create. Usually we want to assign an instance to another variable. C# just assign a reference to a new variable. It is essentially a reference to the same variable. So how can we assign a value while creating a brand new variable instead of just assigning a reference to the instance? We can use the copy constructor.
We can create a constructor for the class that uses only one parameter of the type, such as:
public Student(Student student)
{
= ;
}
Using the constructor above, we can copy a new instance value instead of assigning an instance with the same reference.
class Student
{
private string name;
public Student(string name)
{
= name;
}
public Student(Student student)
{
= ;
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
class Final
{
static void Main()
{
Student student = new Student ("A");
Student NewStudent = new Student (student);
= "B";
("The new student's name is {0}", );
}
}
The new student's name is A.
2. What is a read-only constant
It is a static read-only variable, which is usually assigned values in a static constructor.
class Numbers
{
public readonly int m;
public static readonly int n;
public Numbers (int x)
{
m=x;
}
static Numbers ()
{
n=100;
}
} // where n is a read-only constant, it has only one value for all instances of this class, while m varies according to the instance
three. IDE
1. 2 Please see the original work
3. How to change the color of the region
Foldable text settings via tools à Options à Environment à Font and Color à Foldable Text
Four. WinForm
1. How to make winForm not display the title bar?
Set the form Text property to an empty string and set the ControlBox property to false
= string. Empty;
= false;
2. How to make winform form use XP style
See original work
3. How to prevent form from being displayed in the toolbar
Just set the ShowInTaskbar property of form to false
4. How to make the program open the default mail program with some parameters to let the user start writing mail
1) If it is a web program:
<a href=”mailto:email@,email@?cc=email@&Subject=Hello&body=Happy New Year”>some text</a>
2) For Windows programs, you need to use classes
Process process = new Process();
= "mailto:email@,email@?subject=Hello&cc=email@
&bcc=email@&body=Happy New Year" ;
();
5. How to create a msn prompt window like
You need to get the screen size through (this).Width(Height) property, and then use a timer to change the position of the window according to the time.
five. Button control
1. How to set the default button of form (i.e. the button that is triggered when pressing Enter on form)
The AcceptButton property of form can be set: = button1;
2. How to set the form cancel button (that is, the button triggered when the user presses the Esc key)
The CancelButton property of form can be set: = buttonC;
3. How to trigger a button's Click event through a program
six. Combo Box
1. How to fill Combo Box with optional fonts
();
seven. TextBox
1. How to disable TextBox's default context menu (right-click menu)
= new ContextMenu();
2,3 See the original work
4. How to focus on the end of textBox text when you get focus
= ;
Previous page12Read the full text