因为今天是用的家里的电脑,用的不是retena屏的mac,因此稍后截图的时候大家看到的图片可能会有一些模糊,还请大家海涵。。。

兄弟们,我胡汉三又回来啦!



以下開始我们的第一个C#程序。我们之前已经通过命令行实现了一个简单的可运行程序,看起来不复杂。可是在如今这个讲求效率的时代,用命令行简直弱爆了。因此我们今天用上了高大上的VS。

下载的过程就不赘述了,我们直接看怎样开发一个WinForm程序吧。可能大家有点懵。WinForm是神马玩意,为什么要先学这个呢。

我仅仅能这么简单的跟您说一下:假设我们要做C#开发的话,最好的入门就是做一个WinForm程序。

他事实上类似于VC++的那种可运行程序,仅仅是依托了.Net框架而已。

好的,開始我们的WinForm程序吧:

1.创建程序

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvempoMTcx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

创建成功后看到文件夹结构例如以下:

如图所看到的的Program.cs就是程序的入口。让我们看一下里面的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

当中以下这句话指出了要启动的Form类:

Application.Run(new Form1());

然后我们春藤摸瓜,找到了Form1相应的文件:

一共同拥有三个,从命名就能够大概看出他的意思,

Form1.cs用于写逻辑

Form1.Designer.cs用于画界面

Form1.resx用于管理里面的资源

我们看一下Form1.cs里面的代码:

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
}
}
}

非常稀松寻常的代码,接下来我们拖控件到设计器里面

然后我们更改Form1.cs的代码例如以下:

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.textBox1.Text);
Bitmap bitmap = new Bitmap(uri.LocalPath.ToString());
this.pictureBox1.Image = bitmap;
//图片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(); } }
}

要实现的功能是:点击button。将TextBox这个路径的图片显示到PictureBox这个控件中。

事实上设计器后台的代码也是能够看的,比方本设计器的代码Form.Designer.cs例如以下

namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。 /// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理全部正在使用的资源。
/// </summary>
/// <param name="disposing">假设应释放托管资源。为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗口设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器改动此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.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;
}
}

大功告成!看一下效果:

完...

C#中的Form,textBox,Bitmap,PictureBox,Button,WebBrowser的更多相关文章

  1. ASP.NET 中通过Form身份验证 来模拟Windows 域服务身份验证的方法

    This step-by-step article demonstrates how an ASP.NET   application can use Forms authentication to ...

  2. jQuery中设置form表单中action值与js有什么不同。。。。

    jQuery中设置form表单中action值与js有什么不同.... HTML代码如下: <form action="" method="post" i ...

  3. Django中的Form

    Form 一.使用Form Django中的Form使用时一般有两种功能: 1.生成html标签 2.验证输入内容 要想使用django提供的form,要在views里导入form模块 from dj ...

  4. Javascript中的Form表单知识点总结

    Javascript中的Form表单知识点总结 在HTML中,表单是由form元素来表示的,但是在javascript中,表单则由HTMLFormElement类型,此元素继承了HTMLElement ...

  5. django中的 form 表单操作

     form组件  1. 能做什么事?   1. 能生成HTML代码  input框   2. 可以校验数据   3. 保留输入的数据   4. 有错误的提示   1. 定义   from django ...

  6. 转 Django中的Form

    https://www.cnblogs.com/chenchao1990/p/5284237.html Form 一.使用Form Django中的Form使用时一般有两种功能: 1.生成html标签 ...

  7. 创建dynamics CRM client-side (十三) - 在HTML Web Resource中获取form elements & 获取外部js文件

    上一节我们讨论到创建HTML Web Resource. 但是纯HTML的页面不能满足我们的需求, 所以今天我们来做在HTML Web Resource中获取form elements Please ...

  8. 【译】.NET 5. 0 中 Windows Form 的新特性

    自从 Windows Form 在 2018 年底开源并移植到 .NET Core 以来,团队和我们的外部贡献者都在忙于修复旧的漏洞和添加新功能.在这篇文章中,我们将讨论 .NET 5.0 中 Win ...

  9. jQuery中设置form表单中action的值的方法

    下面介绍在jQuery中设置form表单中action的值的方法. $("#myFormId").attr("action", "userinfo.s ...

  10. html代码中的form参数是基本一致的

    由于pear的大多数模块仍处于开发当中,因此,这里列举的是随着php4.05一起发布的pear中的模块,需要注意的是,一些抽象类或者是基类(如mail.php,log.php,cache.php)没有 ...

随机推荐

  1. XDebug 教程

    安装说明: PHP调试时,不得不提XDEBUG这个调试利器.学习PHP以来,几乎所有的问题我都利用它来解决. 首先关于如何安装,不在赘述,请自行google之.(需要特别注意的是:PHP5.2 和5. ...

  2. [转载]centos 6.4中git如何正常显示中文

    FROM: http://ju.outofmemory.cn/entry/63250 系统版本:centos 6.4 git版本:1.7.1,使用yum直接安装的. 当使用git status查看时, ...

  3. IP地址转化为32位无符号数

    转自 http://blog.csdn.net/testcs_dn/article/details/38585719 一.将ip地址转成long数值 将IP地址转化成整数的方法如下: 1.通过Stri ...

  4. vue2 生命周期

    转:https://segmentfault.com/a/1190000008570622 生命周期先上图 什么是生命周期 Vue实例有一个完整的生命周期,也就是从开始创建.初始化数据.编译模板.挂载 ...

  5. Android动态载入Dex机制解析

    1.什么是类载入器? 类载入器(class loader)是 Java™中的一个非常重要的概念.类载入器负责载入 Java 类的字节代码到 Java 虚拟机中. Java 虚拟机使用 Java 类的方 ...

  6. 大话项目管理工具之Jira篇

    前言 上一篇文章谈的是知识管理工具 -- Confluence,它来自澳大利亚 Atlassian 公司. 非常凑巧的是,今天要介绍的 JIRA 也是来自 Atlassian 公司的.但他不再是知识管 ...

  7. hadoop native本地库问题总结

    近期,打算hbase建表用snappy压缩时,碰到一些hadoop本地库的问题. 事实上这些问题是一直存在的,仅仅是不影响正常使用,就没有引起重视. 这次希望彻底解决下面问题: 问题一:运行start ...

  8. MVC的优缺点

    MVC的优点 大部分用过程语言比如ASP.PHP开发出来的Web应用,初始的开发模板就是混合层的数据编程.例如,直接向数据库发送请求并用HTML显示,开发速度往往比较快,但由于数据页面的分离不是很直接 ...

  9. 一个由正则表达式引发的血案 vs2017使用rdlc实现批量打印 vs2017使用rdlc [asp.net core 源码分析] 01 - Session SignalR sql for xml path用法 MemCahe C# 操作Excel图形——绘制、读取、隐藏、删除图形 IOC,DIP,DI,IoC容器

    1. 血案由来 近期我在为Lazada卖家中心做一个自助注册的项目,其中的shop name校验规则较为复杂,要求:1. 英文字母大小写2. 数字3. 越南文4. 一些特殊字符,如“&”,“- ...

  10. word转pdf

    很多人在工作经常会遇到word转pdf功能,word转pdf还是比较复杂,网上各种包,如python的各种转换包,其实是存在很多问题 的,尤其是对比较复杂的格式,真正的还的是调用组件来转换,这里介绍的 ...