Form,textbox,bitmap,picturebox,button,webbrowser in C #

Source: Internet
Author: User

Because today is the use of the home computer, not Retena screen of the Mac, so later when you see the picture may be some blur, also please Haihan ...


Brothers, I am back again!


Start our first C # program below. We have previously implemented a simple, operational program through the command line, which does not look complicated. But in today's era of efficiency, the command line is simply too weak to explode. So today we're using a big vs.

The download process will not be discussed, we directly see how to develop a WinForm program it. Maybe we are a little confused. WinForm is the god horse thing, why should learn this first.

I can simply tell you this: if we want to do C # development, the best way to get started is to do a WinForm program.

He is in fact similar to VC + + of the kind of running program, just rely on. NET Framework only.

OK, let's start our WinForm program:

1. Create a program

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvempomtcx/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/southeast ">



After the creation succeeds, you see the folder structure such as the following:


The Program.cs you see is the entrance to the program. Let's take a look at the code inside:

Using system;using system.collections.generic;using system.linq;using system.windows.forms;namespace windowsformsapplication1{    Static Class Program {///<summary>//        The main entry point of the application. //        </summary>        [STAThread]        static void Main ()        {            application.enablevisualstyles ();            Application.setcompatibletextrenderingdefault (false);            Application.Run (New Form1 ());}}}    

The following statement indicates the form class to start:

Application.Run (New Form1 ());

Then we spring cane touch melon, found Form1 corresponding files:



A common possession of three, from the name can probably see his meaning,

Form1.cs for writing logic

Form1.Designer.cs for drawing interfaces

Form1.resx to manage the resources inside


Let's take a look at the code inside the Form1.cs:

namespace windowsformsapplication1{public    partial class Form1:form    {public        Form1 ()        {            InitializeComponent ();}}}    

Very unusual code, and then we drag the control into the designer



Then we change the code for Form1.cs such as the following:

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing;    Using system.linq;using system.text;using system.windows.forms;using system.net;namespace WindowsFormsApplication1{            Public partial class Form1:form {public Form1 () {InitializeComponent ();        This.textBox1.Text = "C:\\2.jpg"; } private void Button1_Click (object sender, EventArgs e) {uri uri = new Uri (This.tex            Tbox1.text); Bitmap Bitmap = new Bitmap (URI.            Localpath.tostring ());            This.pictureBox1.Image = bitmap;            Picture uri HttpWebRequest request = (HttpWebRequest) httpwebrequest.create ("http://baidu.com"); Request.            Method = "Get"; WebResponse response = Request.           GetResponse ();            WebBrowser1.Navigate ("http://baidu.com"); Webbrowser1.documenttext = Response.        ToString (); }                   }}

The functions to be implemented are:Click button. Displays a picture of the path to the textbox in the PictureBox control.

In fact, the designer behind the code is also able to see, for example, the code of this designer Form.Designer.cs such as the following

Namespace windowsformsapplication1{partial class Form1 {//<summary>////Required designer variables.

</summary> private System.ComponentModel.IContainer components = null; <summary>///clean up all resources in use. </summary>//<param name= "disposing" > assumes that the managed resource should be released. is true; otherwise false. </param> protected override void Dispose (bool disposing) {if (disposing && (compon Ents = null)) {components. Dispose (); } base. Dispose (disposing); #region the code generated by the Windows window Designer///<summary>///designer supports the required method-do not///Use the Code Editor to change the contents of this method. </summary> private void InitializeComponent () {this.button1 = new system.windows.f Orms. Button (); This.picturebox1 = new System.Windows.Forms.PictureBox (); This.textbox1 = new System.Windows.Forms.TextBox (); This.webbrowser1 = new System.Windows.Forms.WebBrowser (); ((System.ComponentModel.ISupportInitialize) (This.picturebox1)). BeginInit (); This. SuspendLayout (); Button1//this.button1.Location = new System.Drawing.Point (640, 25); This.button1.Name = "Button1"; This.button1.Size = new System.Drawing.Size (157, 37); This.button1.TabIndex = 0; This.button1.Text = "Button1"; This.button1.UseVisualStyleBackColor = true; This.button1.Click + = new System.EventHandler (This.button1_click); PictureBox1//this.pictureBox1.Location = new System.Drawing.Point (12, 58); This.pictureBox1.Name = "PictureBox1"; This.pictureBox1.Size = new System.Drawing.Size (508, 286); This.pictureBox1.TabIndex = 1; This.pictureBox1.TabStop = false; TextBox1//this.textBox1.Location = new System.Drawing.Point (59, 25); This.textBox1.Name = "TextBox1 "; This.textBox1.Size = new System.Drawing.Size (298, 21); This.textBox1.TabIndex = 2; WebBrowser1//this.webBrowser1.Location = new System.Drawing.Point (537, 85); This.webBrowser1.MinimumSize = new System.Drawing.Size (20, 20); This.webBrowser1.Name = "WebBrowser1"; This.webBrowser1.Size = new System.Drawing.Size (250, 250); This.webBrowser1.TabIndex = 3; Form1//this. Autoscaledimensions = new System.Drawing.SizeF (6F, 12F); This. AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; This. ClientSize = new System.Drawing.Size (815, 395); This. Controls.Add (This.webbrowser1); This. Controls.Add (This.textbox1); This. Controls.Add (This.picturebox1); This. Controls.Add (This.button1); This. Name = "Form1"; This. Text = "Form1"; ((System.ComponentModel.ISupportInitialize) (This.picturebox1)). EndInit (); This. ResumeLayout (FALSE); This. PerformLayout (); } #endregion private System.Windows.Forms.Button button1; Private System.Windows.Forms.PictureBox PictureBox1; Private System.Windows.Forms.TextBox TextBox1; Private System.Windows.Forms.WebBrowser WebBrowser1; }}


Done! Look at the effect:



Finish...

Form,textbox,bitmap,picturebox,button,webbrowser in C #

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.