📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace smartMobile
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.ListBox lbData;
public int a;
private bool ifclick;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Thread t = new Thread(new ThreadStart(work_));
t.Start();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.lbData = new System.Windows.Forms.ListBox();
//
// button1
//
this.button1.Location = new System.Drawing.Point(176, 216);
this.button1.Size = new System.Drawing.Size(96, 32);
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(176, 16);
this.textBox1.Size = new System.Drawing.Size(112, 21);
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(176, 56);
this.textBox2.Size = new System.Drawing.Size(112, 21);
this.textBox2.Text = "textBox2";
//
// contextMenu1
//
this.contextMenu1.MenuItems.Add(this.menuItem1);
this.contextMenu1.MenuItems.Add(this.menuItem2);
this.contextMenu1.MenuItems.Add(this.menuItem3);
this.contextMenu1.MenuItems.Add(this.menuItem4);
this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
//
// menuItem1
//
this.menuItem1.Text = "asdfasdfa";
//
// menuItem2
//
this.menuItem2.Text = "sdfsadf";
//
// menuItem3
//
this.menuItem3.Text = "sadfsadfasg";
//
// menuItem4
//
this.menuItem4.Text = "asdfasdf";
//
// lbData
//
this.lbData.Location = new System.Drawing.Point(24, 96);
this.lbData.Size = new System.Drawing.Size(100, 146);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(306, 263);
this.Controls.Add(this.lbData);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
a = 1;
ifclick = true;
// Assembly asm = Assembly.GetExecutingAssembly();
// MessageBox.Show(asm.GetName().Name);
// m_bmpOriginal = new Bitmap(asm.GetManifestResourceStream(asm.GetName().Name + ".MyImage.bmp"));
// // Take the center quarter of m_bmpOriginal
// // and create stetch it into m_bmpZoom of the same size
// m_bmpZoom = new Bitmap(m_bmpOriginal.Width, m_bmpOriginal.Height);
// Graphics gZoom = Graphics.FromImage(m_bmpZoom);
//
// Rectangle srcRect = new Rectangle(m_bmpOriginal.Width / 4, m_bmpOriginal.Height / 4,
// m_bmpOriginal.Width / 2, m_bmpOriginal.Height / 2);
// Rectangle dstRect = new Rectangle(0, 0, m_bmpZoom.Width, m_bmpZoom.Height);
// gZoom.DrawImage(m_bmpOriginal, dstRect, srcRect, GraphicsUnit.Pixel);
}
protected override void OnPaint(PaintEventArgs e)
{
Pen pen = new Pen (Color.Blue);
e.Graphics.DrawRectangle(pen,10,10,40,60);
Font font = new Font("Arial", 12, FontStyle.Regular);
Brush brush = new SolidBrush(Color.Black);
e.Graphics.DrawString("who is who",font,brush,10,10);
Pen pen1 = new Pen(Color.Chartreuse);
e.Graphics.DrawEllipse(pen1,10,10,25,20);
Brush brush1 = new SolidBrush(Color.Bisque);
e.Graphics.FillEllipse(brush1,10,10,25,20);
base.OnPaint (e);
}
private void button1_Click(object sender, System.EventArgs e)
{
if (ifclick)
{
textBox1.Text = "Hello";
textBox2.Text = "world";
ifclick = false;
}
else
{
textBox1.Text = "welcom";
textBox2.Text = "china";
ifclick = true;
}
}
void work_()
{
EventHandler eh = new EventHandler(AddItem);
for (;;)
{
Thread.Sleep(400);
textBox1.Invoke(eh);
}
}
void AddItem(object o, EventArgs e)
{
string line = (string)"know " + a.ToString();
a ++;
lbData.Items.Add(line);
}
private void contextMenu1_Popup(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -