Form1.cs
资源名称:smiley.rar [点击查看]
上传用户:hx800c
上传日期:2020-12-02
资源大小:792k
文件大小:7k
源码类别:
编辑框
开发平台:
Visual Basic
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace PEocxCSharp
- {
- /// <summary>
- /// Form1 的摘要说明。
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private AxWEBRLib.AxWebR axWebR1;
- private AxPEOCXLib.AxPEOcx axPEOcx1;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button3;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Form1()
- {
- //
- // 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()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
- this.axWebR1 = new AxWEBRLib.AxWebR();
- this.axPEOcx1 = new AxPEOCXLib.AxPEOcx();
- this.button1 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- ((System.ComponentModel.ISupportInitialize)(this.axWebR1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.axPEOcx1)).BeginInit();
- this.SuspendLayout();
- //
- // axWebR1
- //
- this.axWebR1.Enabled = true;
- this.axWebR1.Location = new System.Drawing.Point(16, 8);
- this.axWebR1.Name = "axWebR1";
- this.axWebR1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebR1.OcxState")));
- this.axWebR1.Size = new System.Drawing.Size(360, 192);
- this.axWebR1.TabIndex = 0;
- //
- // axPEOcx1
- //
- this.axPEOcx1.Enabled = true;
- this.axPEOcx1.Location = new System.Drawing.Point(16, 232);
- this.axPEOcx1.Name = "axPEOcx1";
- this.axPEOcx1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPEOcx1.OcxState")));
- this.axPEOcx1.Size = new System.Drawing.Size(360, 96);
- this.axPEOcx1.TabIndex = 1;
- this.axPEOcx1.EditKeyDown += new AxPEOCXLib._DPEOcxEvents_EditKeyDownEventHandler(this.axPEOcx1_EditKeyDown);
- this.axPEOcx1.SendFile += new AxPEOCXLib._DPEOcxEvents_SendFileEventHandler(this.axPEOcx1_SendFile);
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(16, 200);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(64, 32);
- this.button1.TabIndex = 2;
- this.button1.Text = "表情";
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(392, 264);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(56, 40);
- this.button3.TabIndex = 4;
- this.button3.Text = "发送";
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(456, 341);
- this.Controls.Add(this.button3);
- this.Controls.Add(this.button1);
- this.Controls.Add(this.axPEOcx1);
- this.Controls.Add(this.axWebR1);
- this.Name = "Form1";
- this.Text = "Form1";
- this.Load += new System.EventHandler(this.Form1_Load);
- ((System.ComponentModel.ISupportInitialize)(this.axWebR1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.axPEOcx1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- Form2 fm = new Form2();
- fm.ShowDialog();
- //目前只加载了第一个目录下的表情
- InsertPics(fm.m_nPicIndex,1, 1);
- }
- //这里插入图片 index是图号(1-99),nPage是目录(1-9), nType=1 表示是表情,2表示是其它硬盘上的图片
- //peocx最多可以插入999个表情,其中可以加载1 - 9 目录,每个目录下可以有0.gif,- 99.gif等
- public void InsertPics(int Index,int nPage, int nType)
- {
- int ind;
- ind = nPage * 100 + Index;
- string strP;//图片路径
- strP = System.IO.Directory.GetCurrentDirectory() + "\Face\" + nPage + "\" + Index + ".gif";
- axPEOcx1.InsertPic( strP, ind, "", nType);
- }
- private void SendMsg(string sMsg)
- {
- //模拟发送和接收,在这里是直接接收
- RecvMsg(sMsg);
- }
- private void RecvMsg(string sMsg )
- {
- string strHtml = axPEOcx1.Txt2Html( sMsg, System.IO.Directory.GetCurrentDirectory() + "\face", 1) + "<br><br>";
- AddHtmlText(strHtml, "PRTX webp2p.com");
- }
- private void button3_Click(object sender, System.EventArgs e)
- {
- SendTxtMsg();
- axPEOcx1.FocusEdit();
- }
- private void Form1_Load(object sender, System.EventArgs e)
- {
- axPEOcx1.SetRTFFont(false, false, false, 0, "宋体",12, false);
- axWebR1.WithScroll = true;
- axWebR1.Width = axWebR1.Width + 1;
- axWebR1.Width = axWebR1.Width - 1;
- }
- private void axPEOcx1_SendFile(object sender, AxPEOCXLib._DPEOcxEvents_SendFileEvent e)
- {
- }
- private void axPEOcx1_EditKeyDown(object sender, AxPEOCXLib._DPEOcxEvents_EditKeyDownEvent e)
- {
- //Debug.Print "P2PEdit_EditKeyDown " & nChar
- if(e.nChar == 999999) //'如果是999999表示按了enter或者ctrl+enter发送
- {
- SendTxtMsg();
- axPEOcx1.FocusEdit();
- }
- }
- private void SendTxtMsg()
- {
- /////////////////////////
- //检查去掉空格和换行符
- //检查不能只有空字符或者换行符号
- string stttt;
- string Str = axPEOcx1.GetSendText();
- //如果是空内容,就直接退出
- if(Str.Length == 0)
- return ;
- int i = Str.IndexOf("\C",0,Str.Length-1);
- stttt = Str.Remove(0, i+2);
- stttt = stttt.Replace('r' ,' '); //回车转成空格
- stttt = stttt.Replace('n' , ' '); //回车转成空格
- stttt = stttt.Trim();
- //如果是空内容,就直接退出
- if(stttt.Length == 0)
- {
- axPEOcx1.ClearRTF();
- return ;
- }
- ///////////////////////////
- ///////现在可以发送了。
- SendMsg(Str); //发送内容
- axPEOcx1.ClearRTF();
- }
- private void AddHtmlText(string sMsg,string sNick )
- {
- string ssH;
- string stime;
- stime = System.DateTime.Now.ToString();
- ssH = sMsg;
- string ss;
- ss = "<font size=2 color=red>" + sNick + "</font>" + " " + "<font size=2>" + stime + "<br>" + "</font>" + ssH;
- axWebR1.AddHTML(ss);
- }
- }
- }