c#窗体设置和Visual studio 2019的应用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 窗体背景图片
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{//当有按键按下时,标题栏显示对应文字,并且显示From2窗体,此时窗体1并不会消失
this.Text = "接受按键";
this.Visible = false;
Form2 frm = new Form2();
frm.Show();
this.Visible = true;
}
private void Form1_Load(object sender, EventArgs e)
{//程序执行,改变窗体的背景图片,设置窗体边框为Sizable
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Text = "装入窗体";
this.BackgroundImage = global::窗体背景图片.Properties.Resources._091910_22094977;//图片引用,启示:添加图片,可以现在对应
//的项目右击找到属性,进去找到资源,把想添加的图片加进去,然后就能用这个语句加入了
}
private void Form1_DoubleClick(object sender, EventArgs e)
{//当双击时,标题栏显示对应文字,显示From2,隐藏From1,当From2关闭后,重新显示from1
this.Text = "双击窗体";
Form2 frm = new Form2();
/* this.Visible = true;*//*默认*/
this.Visible = false;//from1隐藏
frm.ShowDialog();
this.Visible = true;//重新显示
}
/* private void Form1_MinimumSizeChanged(object sender, EventArgs e)
{
this.Text = "窗体尺寸:"+this.Size.ToString();
}*///设计面重置该事件,这里就能改变,如果设置面没有重置,这里改了如向像在这样注释,会导致设计面打不开出错!收获:想要
//添加事件,先在设计面找到,然后再设置事件,想要改也是这样。
private void Form1_SizeChanged(object sender, EventArgs e)
{
this.Text = "窗体尺寸:" + this.Size.ToString();//改变窗体大小时,会在窗体上实时显示整个窗体的大小:宽高
}
private void Form1_LocationChanged(object sender, EventArgs e)
{
this.Text = "窗体位置:" + this.Size.ToString();//显示窗体的位置,不会实时更新
}
}
}