社区
C#
帖子详情
对winform的TextBox,如何以覆盖(overwrite)而不是插入的方式更新其内容?
mxldream
2006-03-24 05:00:29
RT
...全文
382
5
打赏
收藏
对winform的TextBox,如何以覆盖(overwrite)而不是插入的方式更新其内容?
RT
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
mxldream
2006-03-24
打赏
举报
回复
谢谢了
Macosx
2006-03-24
打赏
举报
回复
using System;
http://www.faq-it.org/apache/">faq-it.org/apache/ using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Cmic.Controls
{
/// <summary>
/// TextBoxEx 的摘要说明。
/// </summary>
public class TextBoxInsert : System.Windows.Forms.TextBox
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
enum TypeMode{InsertMode, OvertypeMode};
private TypeMode typeMode;
public TextBoxInsert()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.typeMode = TypeMode.InsertMode;
//
// 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()
{
//
// TextBoxInsert
//
this.Text = "TextBoxEx";
}
#endregion
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged (e);
// if(this.typeMode == TypeMode.InsertMode && this.SelectionLength == 0)
// {
// this.SelectionLength = 1;
// }
if(this.typeMode== TypeMode.OvertypeMode)
{
this.SelectionLength = 1;
}
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
if((e.KeyChar == (char)8) && (typeMode == TypeMode.OvertypeMode))
{
this.SelectionLength = 0;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
switch(e.KeyCode)
{
case Keys.Insert:
if(this.typeMode == TypeMode.OvertypeMode)
{
this.typeMode = TypeMode.InsertMode;
}
else
{
this.SelectionLength = 1;
this.typeMode = TypeMode.OvertypeMode;
}
break;
case Keys.Left:
if(this.typeMode == TypeMode.OvertypeMode)
{
e.Handled=true;
if(this.SelectionStart!=0)
{
this.SelectionStart=this.SelectionStart-1;
this.SelectionLength=1;
}
}
break;
case Keys.Right:
if(this.typeMode == TypeMode.OvertypeMode)
{
e.Handled=true;
if(this.SelectionStart!=this.Text.Length)
{
this.SelectionStart=this.SelectionStart+1;
this.SelectionLength=1;
}
}
break;
default:
break;
}
}
}
}
http://www.faq-it.org/archives/csharp/f33832690ae4b722c81c6f2569fc0b03.php
onlyxuyang
2006-03-24
打赏
举报
回复
晕~~~~~~~~~
这个也可以
写前清空文本框
或者直接 Text=
保证世界清净了
MyLf
2006-03-24
打赏
举报
回复
在keypress事件中
txtbox.SelectionLength= 1;
god14
2006-03-24
打赏
举报
回复
TextBox.Text = "xxx";
c#
winform
使用WebBrowser 大全
C#
WinForm
WebBrowser (一) MSDN资料 1、主要用途:使用户可以在窗体中导航网页。 2、注意:WebBrowser 控件会占用大量资源。使用完该控件后一定要调用 Dispose 方法,以便确保及时释放所有资源。必须在附加事件的同一线程上调用 Dispose 方法,该线程应始终是消息或用户界面 (UI) 线程。 3、WebBrowser 使用下面的成员可以将
winform
图片上传到java服务器_
winform
如何上传图片到服务器
如果想要利用C#通过Socket进行网络传输文件,一般情况下,大家会首先考虑使用.NET自带的Socket.SendFile Method(String)这个方法。不过这个方法没有相应的文件接受方法,而且据说会有8KB的限制。所以,我尝试了另外一种方法,发现效果不错。下面,我就来简单介绍一下其原理。Socket.Send()和Socket.Receive()方法都是传递byte[]的,所以就要想办...
C#
Winform
WebBrowser控件
C#
WinForm
WebBrowser 1、主要用途:使用户可以在窗体中导航网页。 2、注意:WebBrowser控件会占用大量资源。使用完该控件后一定要调用Dispose方法,以便确保及时释放所有资源。必须在附加事件的同一线程上调用Dispose方法,该线程应始终是消息或用户界面(UI)线程。 3、WebBrowser使用下面的成员可以将控件导航到特定URL、在导航...
C#编程-
Winform
基础和ADO.NET
一、
.NET 程序自动
更新
组件
前言本来博主想偷懒使用AutoUpdater.NET组件,但由于博主项目有些特殊性和它的功能过于多,于是博主自己实现一个轻量级独立自动
更新
组件,可稍作修改集成到大家自己项目中,比如:WPF/
Winform
/Windows服务。大致思路:发现
更新
后,从网络上下载
更新
包并进行解压,同时在
WinForm
s 应用程序中显示下载和解压进度条,并重启程序。以提供更好的用户体验。系统架构概览自动化软件
更新
系统...
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章