C#RichTextBox的 RichTextBox.Focus();rtbLog.AppendText(msg);ReadOnly
来源:互联网 发布:生日快乐软件在线制作 编辑:程序博客网 时间:2024/06/07 05:24
垂直滚动条始终在RichTextBox的底部你需要设置HideSelection 为 false 并且用 AppendText来插入新数据例如richTextBox.AppendText("内容");让richTextBox2一直获取焦点则在促发事件的时候增加richTextBox2.Focus();
ReadOnly不可被写改变你内容
View.cs
using System;using SysChargeInterface;namespace AutoSend{ public class View { public static MainForm frm; public static void write(String message) { String time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); String mes = time + ": " + message + "\n"; //如果当前的文本和以前的文本之和 大于文本框的最大长度,进行清空 if (frm.rtbLog.TextLength + mes.Length >= frm.rtbLog.MaxLength) frm.rtbLog.Text = ""; //frm.rtbLog.AppendText(mes); frm.WirtelogTh(mes); } }}
MainForm.cs
using System;using System.Windows.Forms;using AutoSend;namespace SysChargeInterface{ public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void Form1_Load_1(object sender, EventArgs e) { } public void WirtelogTh(String msg) { this.rtbLog.Invoke(new EventHandler(delegate { if (rtbLog.TextLength + msg.Length >= rtbLog.MaxLength) rtbLog.Text = ""; rtbLog.AppendText(msg); rtbLog.Focus(); })); } //getCharge提交订单 Log log = new Log(); private void btnGetCharge_Click(object sender, EventArgs e) { //if (tbxAgentId.Text.ToString() == "" || tbxTelephone.Text.ToString() == "" || tbxTelephoneType.Text.ToString() == "" || tbxMoney.Text.ToString() == "" || tbxChargeMode.Text.ToString() == "" || tbxChargeMode.Text.ToString() == "" || tbxRequestId.Text.ToString() == "" || tbxExtendInfo.Text.ToString() == "" || tbxCallBackUrl.Text.ToString() == "" || tbxGetChargeUrl.Text.ToString() == "" || tbxMD5Key.Text.ToString() == "") //{ // MessageBox.Show("必要参数填写不完整!"); //} //else //{ String SubTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:s");//订单日期 String AgentId = tbxAgentId.Text.ToString(); String Telephone = tbxTelephone.Text.ToString(); String TelephoneType = tbxTelephoneType.Text.ToString(); String Money = tbxMoney.Text.ToString(); String ChargeMode = tbxChargeMode.Text.ToString(); String RequestID = tbxRequestId.Text.ToString(); String ExtendInfo = tbxExtendInfo.Text.ToString(); String CallBackUrl = tbxCallBackUrl.Text.ToString(); String getChargeUrl = tbxGetChargeUrl.Text.ToString(); String MD5Key = tbxMD5Key.Text.ToString(); String para = "AgentID=" + AgentId + "&Telephone=" + Telephone + "&TelephoneType=" + TelephoneType + "&Money=" + Money + "&ChargeMode=" + ChargeMode + "&RequestID=" + RequestID + "&ExtendInfo=" + ExtendInfo + "&CallBackUrl=" + CallBackUrl + "&SubTime=" + SubTime; String Hmac = Share.MD5(para + "&Key=" + MD5Key); String url = getChargeUrl + "/boinf_getCharge.do?" + para + "&Hmac=" + Hmac; AutoSend.View.write("请求Url:" + url); log.Debug("请求Url:" + url); string result = Share.getPage(url, null); AutoSend.View.write("提交返回:"+result); log.Debug("提交返回:" + result); //} } //Query private void btnQuery_Click(object sender, EventArgs e) { //if (tbxAgentId.Text.ToString() == "" || tbxRequestId2.Text.ToString() == "" || tbxOrderID.Text.ToString() == "" || tbxGetBalanceUrl.Text.ToString() == "" || tbxMD5Key.Text.ToString() == "") //{ // MessageBox.Show("必要参数填写不完整!"); //} //else //{ String AgentId = tbxAgentId.Text.ToString(); String RequestID = tbxRequestId2.Text.ToString(); String OrderID = tbxOrderID.Text.ToString(); String getBalanceUrl = tbxGetBalanceUrl.Text.ToString(); String MD5Key = tbxMD5Key.Text.ToString(); String para = "AgentID=" + AgentId + "&OrderID=" + OrderID + "&RequestID=" + RequestID; String Hmac = Share.MD5(para + "&Key=" + MD5Key); String url = getBalanceUrl + "/boinf_QueryChargeRecord.do?" + para + "&Hmac=" + Hmac; AutoSend.View.write("请求Url:" + url); log.Debug("请求Url:" + url); string result = Share.getPage(url, null); AutoSend.View.write("充值结果查询返回:" + result); log.Debug("充值结果查询返回:" + result); //} } private void btnGetBalance_Click(object sender, EventArgs e) { //if (tbxAgentId.Text.ToString() == "" || tbxQueryUrl.Text.ToString() == "" || tbxMD5Key.Text.ToString() == "") //{ // MessageBox.Show("必要参数填写不完整!"); //} //else //{ String AgentId = tbxAgentId.Text.ToString(); String queryUrl = tbxQueryUrl.Text.ToString(); String MD5Key = tbxMD5Key.Text.ToString(); String para = "AgentID=" + AgentId; String Hmac = Share.MD5(para + "&Key=" + MD5Key); String url = queryUrl + "/boinf_getBalance.do?" + para + "&Hmac=" + Hmac; AutoSend.View.write("请求Url:" + url); log.Debug("请求Url:" + url); string result = Share.getPage(url, null); AutoSend.View.write("代理商查询返回:" + result); log.Debug("代理商查询返回:" + result); //} } }}
Program.cs
using System;using System.Collections.Generic;using AutoSend;using System.Windows.Forms;namespace SysChargeInterface{ static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm frm = new MainForm(); AutoSend.View.frm = frm; Application.Run(frm); } }}