比如说,现在的textbox.width=100,而我要让他认为只有50,前面和后面各空出30,20的空间,在这空间之内不能输入信息,就相当于看上去是100长度的textbox其实只有50长度
解决方案 »
- Oracle数据库查询问题
- c# 图片保存出现ORA-25153 临时表空间为空, 无法将图片保存到库中
- 请问有没有什么办法能把注释文档提取出来?
- 关于Console的问题
- 在ListBox的SelectedIndexChanged事件中可以得到之前选中的Item吗?
- 一个简单的Icon设置问题
- 求Microsoft Visual Studio .NET 2003 七CD下载地址呀
- 怎样隐藏PropertyGrid中的集合编辑器
- 关于多用户操作同一条数据的时候,怎样避免错误
- 在线等待:C#中自定义一个函数,有一参数object,我怎么得到这个object 什么控件?
- 无法将类型“System.IO.StreamWriter”隐式转换为“StreamWriter”
- 如何确定local machine是否能访问某特定url
this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;是不是让文本居中呢?是的话设置属性就可以了
你的最终目的是什么,大家不是很清楚只能猜,没法帮你想一个最好的办法你可以自己做个控件,画个假的textbox中间放个没边框的textbox...
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); TextBoxEx textBox = new TextBoxEx();
textBox.TextMargin = new TextMargin(30, 20);
textBox.Width = 100;
this.Controls.Add(textBox);
} public class TextBoxEx : TextBox
{
private TextMargin _textMargin = new TextMargin(); public TextMargin TextMargin
{
get
{
return this._textMargin;
}
set
{
if (_textMargin != value)
{
_textMargin = value;
this.UpdateTextMargin();
}
}
} protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
this.UpdateTextMargin();
} private void UpdateTextMargin()
{
if (!Form1.TextMargin.IsEmpty(this._textMargin) && this.IsHandleCreated)
{
SendMessage(this.Handle, EM_SETMARGINS, new IntPtr(EC_LEFTMARGIN | EC_RIGHTMARGIN), this._textMargin.ToWin32TextMargin);
}
} private const uint EM_SETMARGINS = 0x00D3; private const uint EC_LEFTMARGIN = 0x0001;
private const uint EC_RIGHTMARGIN = 0x0002; [DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr hParem, IntPtr lParam);
} public struct TextMargin
{
private int _left;
private int _right; public TextMargin(int left, int right)
{
_left = left;
_right = right;
} public int Left
{
get { return _left; }
set { _left = value; }
} public int Right
{
get { return _right; }
set { _right = value; }
} public IntPtr ToWin32TextMargin
{
get { return new IntPtr( this._left | (this._right << 16)); }
} public static bool IsEmpty(TextMargin value)
{
return value== null || ( value._left == 0 && value._right == 0) ;
} public static bool operator ==(TextMargin left, TextMargin right)
{
if (left != null && right != null)
{
return left._left == right._left && left._right == right._right;
} return left == null && right == null;
} public static bool operator !=(TextMargin left, TextMargin right)
{
return !(left == right);
}
}
}
}