Form2.cs
资源名称:smiley.rar [点击查看]
上传用户:hx800c
上传日期:2020-12-02
资源大小:792k
文件大小:3k
源码类别:
编辑框
开发平台:
Visual Basic
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace PEocxCSharp
- {
- /// <summary>
- /// Form2 的摘要说明。
- /// </summary>
- public class Form2 : System.Windows.Forms.Form
- {
- public int m_nPicIndex;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Form2()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- //
- // Form2
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.BackColor = System.Drawing.SystemColors.Control;
- this.ClientSize = new System.Drawing.Size(280, 144);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
- this.Name = "Form2";
- this.Text = "Form2";
- this.Load += new System.EventHandler(this.Form2_Load);
- }
- #endregion
- private void Form2_Load(object sender, System.EventArgs e)
- {
- m_nPicIndex = 1; //初始化值
- //加载按扭数组
- const int num = 44;
- Button[] btns = new Button[num];
- for(int i = 0; i < num; i++)
- {
- int x = 26; //表情宽
- int y = 26; //表情高
- int xNum = 10 ; //一行多少个
- btns[i] = new Button();//这一句往往为初学者忽视,须知要创建对象的实例!
- btns[i].Location = new System.Drawing.Point((x + 2) * (i % xNum), (y+2) * (i / xNum));
- btns[i].Name = "btnTest";
- btns[i].Size = new System.Drawing.Size(x, y);
- //btns[i].Text = i.ToString();
- btns[i].FlatStyle = System.Windows.Forms.FlatStyle.Popup ;
- int j = i + 1;
- btns[i].Image = System.Drawing.Image.FromFile(System.IO.Directory.GetCurrentDirectory() + "\Face\1\" + j + ".gif");
- //System.Drawing.Bitmap.FromFile(System.IO.Directory.GetCurrentDirectory() + "\Face\1\" + j + ".bmp");
- btns[i].ImageAlign = System.Drawing.ContentAlignment.MiddleCenter ;
- btns[i].Click += new System.EventHandler(this.btns_Click);//统一的事件处理
- btns[i].Tag = j;
- btns[i].BackColor = System.Drawing.Color.White ;
- this.Controls.Add(btns[i]);//在窗体上呈现控件
- }
- }
- private void btns_Click(object sender, System.EventArgs e)
- {
- m_nPicIndex =System.Convert.ToInt32(((Button)sender).Tag);
- //MessageBox.Show(((Button)sender).Tag + " was clicked !");//通过sender判断激发事件的控件
- this.Close();
- }
- }
- }