WinForm - 也叫做C/S  客户端

另:B/S是 网页端

客户端应用程序 - 是需要安装在用户电脑上才可以使用的程序

特点: 不需要联网也可以打开使用部分功能,但是现在的情况是许多功能依然需要互联网的支持,代码部分在用户电脑上执行

使用VS新建项目-Windows窗体应用程序

在打开的设计界面上,右击窗口点击属性,即可设置窗体本身的各种属性:

布局:

AutoScroll:当窗体中内容超出可见区域时,自动显示滚动条

Location:窗体距离桌面左上角的距离坐标,需要配合StartPosition中的Manual使用

MaximumSize:窗体可以调整到的最大大小

MinimumSize:窗体可以调整到的最小大小

Size:窗体的大小

StartPosition:确定窗体第一次出现时(打开时)的位置 Manual:配合Location设置距离桌面左上角的距离 CenterScreen:根据桌面居中

WindowState:窗体打开时的状态(普通 最小化 最大化)

窗口样式:

Icon:窗体的图标(在窗体左上角以及下方任务栏中显示的图标)

MaximizeBox:确定窗体标题栏右上角是否有最大化框(设置是否可用)

MinimizeBox:确定窗体标题栏的右上角是否有最小化框(单独设置则为灰色不可用 如果最小化最大化都设置为false 则二者都不显示)

Opacity:窗体透明度

ShowInTaskbar:确定窗体是否出现在Windows任务栏中(桌面下方任务栏)

TopMost:设置是否在顶层(分顶层和底层 顶层窗体可以遮挡住所有底部窗体 同层窗体可互相遮挡)

设计:

Name:窗体的名字(在程序中使用的 并非窗口显示的标题)

外观:

BackColor:背景颜色

Backgroundimage:背景图片(最好导入到项目中使用)

BackgroundimageLayout:设置背景图片布局

Cursor:设置鼠标悬浮时的样式

Font:字体设置

ForeColor:前景颜色(文本)

FromBorderStyle:窗体边框和标题栏的外观样式(FixedSingle 不可调整大小 Sizeble 默认 None 无边框和标题栏)

Text:窗体的标题栏文字

不规则窗体:

例:把加速球放到记事本框中并截图,此时图片背景是白色,利用窗口样式中的TransparencyKey属性(绘制到窗体上时显示为透明的颜色)设置为白色,所有白色背景都会变为透明,然后去掉边框,即可制作出不规则窗体

窗体的几个类型:

1、记事本(可随意调整大小和位置)

2、计算器(不可调整大小 并且最大化按钮不可用)

3、美观的窗体(类似QQ、杀毒软件等成品软件界面)

4、不规则窗体

六个最常用的控件:

1、Label 专门用来在窗体上写文本使用 文本写在Text属性里 AutoSize(根据文本内容自动调整大小)

2、ComboBox 下拉框 可在此控件右上方小箭头点击选择编辑项 在里面添加内容

3、RadioButton 单选框 只能选择其中一个 果想将某个单选框内容设置为默认选择 将其Checked属性设置为True即可

4、CheckBox 复选框 可以多选

5、TextBox 文本框 默认一行 点击右上角三角 勾选上MultiLine 即可自己控制文本框大小

6、Button 按钮  name设置按钮名 Text设置按钮显示的文字 双击进入设置按钮的事件(默认为点击事件)

练习:制作肯德基点餐系统

namespace WindowsFormsApplication2
{
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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.label4 = new System.Windows.Forms.Label();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("微软雅黑", 20F, System.Drawing.FontStyle.Bold);
this.label1.ForeColor = System.Drawing.Color.Yellow;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "肯德基点餐系统";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label2
//
this.label2.AutoSize = true;
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Font = new System.Drawing.Font("宋体", 10F);
this.label2.ForeColor = System.Drawing.Color.White;
this.label2.Location = new System.Drawing.Point(, );
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(, );
this.label2.TabIndex = ;
this.label2.Text = "请选择主食:";
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"田园鸡腿堡",
"香辣鸡腿堡",
"老北京鸡肉卷",
"墨西哥鸡肉卷"});
this.comboBox1.Location = new System.Drawing.Point(, );
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(, );
this.comboBox1.TabIndex = ;
//
// label3
//
this.label3.AutoSize = true;
this.label3.BackColor = System.Drawing.Color.Transparent;
this.label3.Font = new System.Drawing.Font("宋体", 10F);
this.label3.ForeColor = System.Drawing.Color.White;
this.label3.Location = new System.Drawing.Point(, );
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(, );
this.label3.TabIndex = ;
this.label3.Text = "请选择配餐:";
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.BackColor = System.Drawing.Color.Transparent;
this.radioButton1.Checked = true;
this.radioButton1.ForeColor = System.Drawing.Color.White;
this.radioButton1.Location = new System.Drawing.Point(, );
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(, );
this.radioButton1.TabIndex = ;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "薯条";
this.radioButton1.UseVisualStyleBackColor = false;
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.BackColor = System.Drawing.Color.Transparent;
this.radioButton2.ForeColor = System.Drawing.Color.White;
this.radioButton2.Location = new System.Drawing.Point(, );
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(, );
this.radioButton2.TabIndex = ;
this.radioButton2.Text = "土豆泥";
this.radioButton2.UseVisualStyleBackColor = false;
//
// radioButton3
//
this.radioButton3.AutoSize = true;
this.radioButton3.BackColor = System.Drawing.Color.Transparent;
this.radioButton3.ForeColor = System.Drawing.Color.White;
this.radioButton3.Location = new System.Drawing.Point(, );
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(, );
this.radioButton3.TabIndex = ;
this.radioButton3.Text = "鸡米花";
this.radioButton3.UseVisualStyleBackColor = false;
//
// label4
//
this.label4.AutoSize = true;
this.label4.BackColor = System.Drawing.Color.Transparent;
this.label4.Font = new System.Drawing.Font("宋体", 10F);
this.label4.ForeColor = System.Drawing.Color.White;
this.label4.Location = new System.Drawing.Point(, );
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(, );
this.label4.TabIndex = ;
this.label4.Text = "请选择饮品:";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.BackColor = System.Drawing.Color.Transparent;
this.checkBox1.ForeColor = System.Drawing.Color.White;
this.checkBox1.Location = new System.Drawing.Point(, );
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(, );
this.checkBox1.TabIndex = ;
this.checkBox1.Text = "可乐";
this.checkBox1.UseVisualStyleBackColor = false;
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.BackColor = System.Drawing.Color.Transparent;
this.checkBox2.ForeColor = System.Drawing.Color.White;
this.checkBox2.Location = new System.Drawing.Point(, );
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(, );
this.checkBox2.TabIndex = ;
this.checkBox2.Text = "热牛奶";
this.checkBox2.UseVisualStyleBackColor = false;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// checkBox3
//
this.checkBox3.AutoSize = true;
this.checkBox3.BackColor = System.Drawing.Color.Transparent;
this.checkBox3.ForeColor = System.Drawing.Color.White;
this.checkBox3.Location = new System.Drawing.Point(, );
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(, );
this.checkBox3.TabIndex = ;
this.checkBox3.Text = "咖啡";
this.checkBox3.UseVisualStyleBackColor = false;
//
// label5
//
this.label5.AutoSize = true;
this.label5.BackColor = System.Drawing.Color.Transparent;
this.label5.Font = new System.Drawing.Font("宋体", 10F);
this.label5.ForeColor = System.Drawing.Color.White;
this.label5.Location = new System.Drawing.Point(, );
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(, );
this.label5.TabIndex = ;
this.label5.Text = "请输入地址:";
this.label5.Click += new System.EventHandler(this.label5_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(, );
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(, );
this.textBox1.TabIndex = ;
//
// label6
//
this.label6.AutoSize = true;
this.label6.BackColor = System.Drawing.Color.Transparent;
this.label6.Font = new System.Drawing.Font("宋体", 10F);
this.label6.ForeColor = System.Drawing.Color.White;
this.label6.Location = new System.Drawing.Point(, );
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(, );
this.label6.TabIndex = ;
this.label6.Text = "请输入电话:";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(, );
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(, );
this.textBox2.TabIndex = ;
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Gainsboro;
this.button1.Cursor = System.Windows.Forms.Cursors.Hand;
this.button1.Font = new System.Drawing.Font("微软雅黑", 15F);
this.button1.ForeColor = System.Drawing.Color.Red;
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "提交";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::WindowsFormsApplication2.Properties.Resources._1;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.checkBox3);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.radioButton3);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "肯德基点餐系统";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
}
}
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; namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.SelectedIndex = ;//设置下拉框的默认值为第一行数据而不是为空
} private void button1_Click(object sender, EventArgs e)
{
//主食
string zs = comboBox1.SelectedItem.ToString();
//配餐
string pc = "";
if (radioButton1.Checked)//判断是否选中
pc = radioButton1.Text;
else if(radioButton2.Checked)
pc = radioButton2.Text;
else
pc = radioButton3.Text;
//饮品
string yp = "";
if (checkBox1.Checked)//判断饮品1是否选中
yp += checkBox1.Text;
if (checkBox2.Checked)
{
if (yp != "")//如果前面已经有选择过的饮品就加逗号
{
yp += ",";
}
yp += checkBox2.Text;
}
if (checkBox3.Checked)
{
if (yp != "")
{
yp += ",";
}
yp += checkBox3.Text;
}
//地址
string dz = textBox1.Text;
//电话
string tel = textBox2.Text;
MessageBox.Show("您选的的主食是:"+zs+"\r您选择的配餐是:"+pc+"\r您选择的饮品是:"+yp+"\r配送地址:"+dz+"\r联系电话:"+tel); } private void Form1_Load(object sender, EventArgs e)
{ } private void checkBox2_CheckedChanged(object sender, EventArgs e)
{ } private void label5_Click(object sender, EventArgs e)
{ }
}
}

winform基础窗体设置及基础控件的更多相关文章

  1. c# Winform 继承窗体 无法拖动修改控件大小

    问题描述: 一个窗体集成父窗体,发现无法直接拖动修改的控件,比如修改大小等 特征: 不禁使父窗体控件,就算新加一个控件也会这样:鼠标放到控件移动手方块上会出现一个“继承的控件”的tooptip, 异常 ...

  2. 关于WinForm引用WPF窗体---在Winform窗体中使用WPF控件

    项目中有个界面展示用WPF实现起来比较简单,并且能提供更酷炫的效果,但是在WinForm中使用WPF窗体出现了问题,在网上找了一下有些人说Winform不能引用WPF的窗体,我就很纳闷,Win32都能 ...

  3. SharePoint2010沙盒解决方案基础开发——关于TreeView树形控件读取列表数据(树形导航)的webpart开发及问题

    转:http://blog.csdn.net/miragesky2049/article/details/7204882 SharePoint2010沙盒解决方案基础开发--关于TreeView树形控 ...

  4. 在Winform窗体中使用WPF控件(附源码)

    原文:在Winform窗体中使用WPF控件(附源码) 今天是礼拜6,下雨,没有外出,闲暇就写一篇博文讲下如何在Winform中使用WPF控件.原有是我在百度上搜索相关信息无果,遂干脆动手自己实现. W ...

  5. WinForm 鼠标进入移开窗体事件,因子控件导致的误触发

    /// <summary> /// 重写OnControlAdded方法,为每个子控件添加MouseLeave事件 /// </summary> /// <param n ...

  6. (转)C# WinForm中 获得当前鼠标所在控件 或 将窗体中鼠标所在控件名显示在窗体标题上

    原文地址:http://www.cnblogs.com/08shiyan/archive/2011/04/14/2015758.html /********************** * 课题:将窗 ...

  7. Winform中怎样在工具类中对窗体中多个控件进行操作(赋值)

    场景 需求是在窗体加载完成后掉用工具类的方法,工具类中获取窗体的多个控件对象进行赋值. 注: 博客主页: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 ...

  8. [WinForm]WinForm跨线程UI操作常用控件类大全

    前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作.不过会有一个问题:就是涉及到跨线程操作UI元素. 相信才开始接触的人一定会遇上这个问题. 为了解决这个问 ...

  9. SNF开发平台WinForm之三-开发-单表选择控件创建-SNF快速开发平台3.3-Spring.Net.Framework

    3.1运行效果: 3.2开发实现: 3.2.1 这个开发与第一个开发操作步骤是一致的,不同之处就是在生成完代码之后,留下如下圈红程序,其它删除. 第一个开发地址:开发-单表表格编辑管理页面 http: ...

随机推荐

  1. Resource Acquisition Is Initialization(RAII Idiom)

    原文链接:http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Resource_Acquisition_Is_Initialization Intent ...

  2. [python实现设计模式]-5.迭代器模式-一起撸串嗨皮啦

    迭代器模式是一个我们经常使用但是出境不高的模式. 为啥捏?因为大部分的语言都帮我们实现了细节,我们不许关注他的实现就能用的很嗨皮了. 不管怎样.这也是个非常常用的模式. 俗话说得好,这个世界上没有事情 ...

  3. long l=88;这个表达式是正确的,因为long比int类型大,会发生自动转换

    long l=88;这个表达式是正确的,因为long比int类型大,会发生自动转换

  4. ios 给uiview创作遮罩

    mask一定是PNG格式的图像,去掉背景 .jpg格式图片没有alpha values 遮罩是通过图片透明度的信息实现与颜色无关 UIImage*_maskingImage =[UIImage ima ...

  5. C#画线源码

    画线 private void Form1_Load(object sender, EventArgs e) { this.Paint += new PaintEventHandler(Form1_P ...

  6. [转]Putty中文乱码解决方法

    from: http://www.putty.ws/putty-luanma putty使用的过程中,你是否遇到过putty出现中文乱码的情况呢?putty终端出现乱码,是情况,多数是由于系统或软件缺 ...

  7. Eclipse改变外观,护眼模式

    1.Eclipse改变背景颜色 Windows menu --> Preference General -> Editors -> Text Editors(click),  在右下 ...

  8. 内容自适应UILabel

    xcode 6.1 File-New-Project.. iOs-Application-Simple View Application 代码: - (void)viewDidLoad { [supe ...

  9. hive编程指南--employees表数据定义

    hive编程指南中有个employees表,默认的分隔符比較繁杂,编辑起来不太方便(普通编辑器编辑的控制字符^A等被当成字符串处理了,没有起到分隔符的作用). 收集的解决方式例如以下: http:// ...

  10. 九种迹象表明你该用Linux了

    实际上.你每天都或多或少的不知不觉地在使用Linux系统. 在webserver领域中,Linux是占主导地位的操作系统.包含你如今正在浏览的页面的后台,都是跑在Linux上的.甚至你整天不离手的An ...