Modifications in C #

Source: Internet
Author: User

This article is from Mukund Pujari's "Some cool Tips for. NET", I give you a summary of my English level is so, not the right place or please put forward.

1. How do I create a form that can change size without a title bar? (How to create a form with resizing borders and no title bar?)

Form1. Text = string. Empty;
Form1. ControlBox = false;


2. How to get in. NET, enable the XP topic set on Windows Forms? (How do XP Themes with Windows Forms using the. NET?)

Verify that the FlatStyle property in your control has been modified to system, and then modify the main method.

static void Main ()
{
Application.enablevisualstyles ();
Application.doevents ();
Application. Run (New Form1 ());
}


3. How do I set a default button for a form? (How to set the default button for a form?)

Form1. AcceptButton = button1;

4. How do I set a Cancel button for a form? (How to set the Cancel button for a form?)

Form1. CancelButton = button1;

5. How do I prevent a form title from appearing on the taskbar? (How to prevent a form from being shown in the taskbar?)

Set the ShowInTaskbar property of the form to false

6. How do I bind to the ComboBox control with the available fonts? (How to fill a ComboBox with the available fonts?)

ComboBox1.Items.AddRange (fontfamily.families);

7. How do I disable the default mail menu for textbox controls? (How to disable the default ContextMenu of a TextBox?)

Textbox1.contextmenu = new ContextMenu ();

8. How do I get some system folder paths such as "My Documents"? How do I get the path for ' my Documents ' and other system folders?

Some system folder information is included in the Environment.SpecialFolder
MessageBox.Show (Environment.getfolderpath (Environment.SpecialFolder.Personal));

9. How do I get the path that the application is currently executing? How do I get the path to my running EXE?

string apppath = Application.executablepath;

10. How do I determine which system is currently running? (Determine which operating system is running?)

OperatingSystem os = environment.osversion;
MessageBox.Show (OS. Version.tostring ());
MessageBox.Show (OS. Platform.tostring ());

11. How do I get the filename from the full path? (How to get a file ' s name from the complete path string?)

Methods with System.IO.Path.GetFileName and System.IO.Path.GetFileNameWithoutExtension (no extension)

12. How do I get the file name extension from the full path? (How to get a file ' s extension from the complete path string?)

Using System.IO.Path.GetExtension method

13. How do I make a DateTimePicker control without a select date blank text? (How do you datetimepicker show empty text if no date is selected?)

Datetimepicker1.customformat = "";
Datetimepicker1.format = Datetimepickerformat.custom;

14. How to hide the status bar of the crystal in the show viewer? (How to hide the status bar, Crystal, in the "Viewer")

foreach (Object obj in This.crystalReportViewer1.Controls)
{
if (obj. GetType () = = typeof (System.Windows.Forms.StatusBar))
{
StatusBar sbar= (StatusBar) obj;
Sbar.visible=false;
}
}


15. How do I use Crystal to generate PDF versions? (How to generate PDF version of Crystal the programmatically?)

Reportdocument o_report=new reportdocument ();
Exportoptions exportopts = new Exportoptions ();
Pdfrtfwordformatoptions pdfformatopts = new Pdfrtfwordformatoptions ();
Diskfiledestinationoptions diskopts = new Diskfiledestinationoptions ();
exportopts = o_report.exportoptions;
Set PDF format
Exportopts.exportformattype = Exportformattype.portabledocformat;
Exportopts.formatoptions = pdfformatopts;
Setting file options and exporting
Exportopts.exportdestinationtype = Exportdestinationtype.diskfile;
Diskopts.diskfilename = "C://trial.pdf"; To set the PDF export path
Exportopts.destinationoptions = diskopts;
O_report.export ();


16. How do I enter multiple lines of text through code? (How do I enter multiline text in TextBox through code?) )

Using the Lines property of a TextBox control
string [] straddress = {"Mukund Pujari", "Global Transformation Technologies", "Pune, India"};
Textbox1.multiline=true;
textbox1.lines=straddress;

Or
textbox1.text= "line 1\r\nline2\r\nline3."

Or
Substituting "System.Environment.NewLine" for line-wrapping symbols

17. How do I remove the checkbox uncertainty in the DataGrid? (How to remove the indeterminate status of a checkbox in DataGrid?)

DataGridTableStyle ts1 = new DataGridTableStyle (); CREATE TABLE Style
Ts1. MappingName = "Items"; Assign a data Table to which you want to apply a style
DataGridColumnStyle Boolcol = new DataGridBoolColumn (); To create a checkbox column
boolcol.mappingname = "ch"; Assigning data column names
Boolcol.allownull=false; Modify the Allownull property

18. How do you bind two controls with a data source DataTable to ensure that the changes are not reflected in two controls? (How to bind two controls to the same DataTable without have changes in one control also change the "other" control?)

We place a ListBox and a ComboBox control in a form, and when the data source is a DataTable and the bound ValueMember coincide we select an item in the ListBox, The same item in the ComboBox control is also automatically selected, and we can take a new context bound object to reject such a synchronization operation
Combobox1.datasource = DataSet. tables["Items"];
Combobox1.valuemember = "CustomerID";
Combobox1.displaymember = "CustomerID";

Listbox1.bindingcontext = new BindingContext (); Setting a new context-bound object
Listbox1.datasource = DataSet. tables["Items"];
Listbox1.valuemember = "CustomerID";
Listbox1.displaymember = "CustomerID";

19. A simple way to create a link string. (An easy way to build connection string.)

Notepad to create a new.udl file, a Microsoft Data link file
Double-click Open, Familiar.
Follow the wizard to create a complete database link to test successfully
When OK, the link string is written to this file, opened with Notepad and you see the

20. How to open client-side e-mail programs, Windows applications and Web applications? (How to open default e-mail client on your system and all parameters entered in It,like Outlook Express or Eudora, from Your. NET windows or WEB application? )

WEB Application:
A href= "Mailto:email@address1.com,email@address2.com?cc=email@address3.com&subject=hello&body=happy New Year "

Windows Application:
Referencing System.Diagnostics.Process namespaces
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 ();

VB. What is the difference between NET and C #? (What is Difference beween vb.net and c#.net?) )

Go to Microsoft to download a document, Http://download.microsoft.com/download/6/3/5/6354bf47-c597-4029-89e9-2495e7539ab9/vbcsharpwp.exe

How do I find whether your system has mouse or the number of buttons, whether it has wheel, or whether the mouse buttons are swapped or size of your monitor and many such information?

23. How do I make a panel or label control translucent on a Windows Form? (How do a Panel or Label semi-transparent on a Windows Form?) )

By setting the alpha value of the control's background color
Panel1. BackColor = Color.FromArgb (65, 204, 212, 230);
Note: Manually enter these values at design time and do not use color selection

What is the purpose of writing [STA Thread] Properties for the main function of a C # program? (What is the purpose's [STA Thread] attribute for the Main method of a C # program? )

http://community.csdn.net/Expert/topic/4132/4132313.xml?temp=.2285272


25. How do I trigger the button click event? (How to trigger a button click event?) )

Button1. PerformClick ();




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.