⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 C#编程百例,是一个入门的学习好帮助,有兴趣的可以下回去看看!
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;


namespace imageView
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
        private TestForm tfForm;
        private System.Windows.Forms.PictureBox pbPicture;
        private System.Windows.Forms.Button btnClose;
        private System.Windows.Forms.Button btnBrowser;
        private System.Windows.Forms.Button button1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
            this.tfForm = new TestForm();
            
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.btnBrowser = new System.Windows.Forms.Button();
            this.pbPicture = new System.Windows.Forms.PictureBox();
            this.btnClose = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // btnBrowser
            // 
            this.btnBrowser.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnBrowser.Location = new System.Drawing.Point(48, 248);
            this.btnBrowser.Name = "btnBrowser";
            this.btnBrowser.TabIndex = 2;
            this.btnBrowser.Text = "浏览(&B) ";
            this.btnBrowser.Click += new System.EventHandler(this.btnBrowser_Click);
            // 
            // pbPicture
            // 
            this.pbPicture.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.pbPicture.BackColor = System.Drawing.SystemColors.ControlDark;
            this.pbPicture.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.pbPicture.Cursor = System.Windows.Forms.Cursors.Hand;
            this.pbPicture.Name = "pbPicture";
            this.pbPicture.Size = new System.Drawing.Size(316, 252);
            this.pbPicture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
            this.pbPicture.TabIndex = 0;
            this.pbPicture.TabStop = false;
            // 
            // btnClose
            // 
            this.btnClose.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnClose.Location = new System.Drawing.Point(168, 248);
            this.btnClose.Name = "btnClose";
            this.btnClose.TabIndex = 1;
            this.btnClose.Text = "关闭(&C)  ";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(256, 256);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(40, 16);
            this.button1.TabIndex = 3;
            this.button1.Text = "button1";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(304, 277);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.button1,
                                                                          this.btnBrowser,
                                                                          this.btnClose,
                                                                          this.pbPicture});
            this.Name = "ImageForm";
            this.Text = "图片浏览";
            this.ResumeLayout(false);

          

        }
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

        private void btnClose_Click(object sender, System.EventArgs e)
        {
            //关闭程序
            //Application.Exit();
            this.Close();
           
        }

        private void btnBrowser_Click(object sender, System.EventArgs e)
        {
            //打开目录对话框,选中图片文件
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "选择图片";
            fdlg.InitialDirectory = "c:\\";
            //文件过滤类型
            fdlg.Filter = "All files (*.*)|*.*|Image files (*.jpg, *.bmp, *.gif)|*.jpg; *.bmp; *.gif" ; 
            //缺省
            fdlg.FilterIndex = 2 ; 
            //fdlg.RestoreDirectory = true ; 
            if(fdlg.ShowDialog() == DialogResult.OK) 
            { 
                pbPicture.Image = Image.FromFile(fdlg.FileName) ; 
            } 
            //Invalidate(); 
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            tfForm.Show();

        }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -