C# 如何设置 richTextBoxr的边距
附件 http://files.cnblogs.com/xe2011/richTextBox_EM_SETRECT.rar

using System.Runtime.InteropServices; public struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
} [DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, ref Rect lParam);// private const int EM_GETRECT = 0x00b2;
private const int EM_SETRECT = 0x00b3; public Rect RichTextBoxMargin
{
get
{
Rect rect = new Rect();
SendMessage(richTextBox1.Handle, EM_GETRECT, IntPtr.Zero, ref rect);
rect.Left += ;
rect.Top += ;
rect.Right = + richTextBox1.ClientSize.Width - rect.Right;
rect.Bottom = richTextBox1.ClientSize.Height - rect.Bottom;
return rect;
}
set
{
Rect rect;
rect.Left = richTextBox1.ClientRectangle.Left + value.Left;
rect.Top = richTextBox1.ClientRectangle.Top + value.Top;
rect.Right = richTextBox1.ClientRectangle.Right - value.Right;
rect.Bottom = richTextBox1.ClientRectangle.Bottom - value.Bottom; SendMessage(richTextBox1.Handle, EM_SETRECT, IntPtr.Zero, ref rect);
} } //设置
private void button1_Click(object sender, EventArgs e)
{
Rect rect;
rect.Left = ;
rect.Top = ;
rect.Right = ;
rect.Bottom = ; RichTextBoxMargin = rect;
} //获得
private void button2_Click(object sender, EventArgs e)
{
Rect rect;
rect = RichTextBoxMargin; MessageBox.Show( string.Format("Left = {0} top={1} right={2} bottom={3}",rect.Left,rect.Top,rect.Right,rect.Bottom));
}
放在自定义的类里面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; namespace System.Windows.Forms
{
public class CustomRichTextBox:RichTextBox
{
public CustomRichTextBox()
{
richTextBox1=this;
}
private System.Windows.Forms.RichTextBox richTextBox1; private struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
} [DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, ref Rect lParam); private const int EM_GETRECT = 0x00b2;
private const int EM_SETRECT = 0x00b3; /// <summary>
/// 当没设置的时候结果多出了L T R +2
/// </summary>
private Rect RichTextBoxMargin
{
get
{
Rect rect = new Rect();
SendMessage(richTextBox1.Handle, EM_GETRECT, IntPtr.Zero, ref rect);
rect.Left += ;
rect.Top += ;
rect.Right = + richTextBox1.DisplayRectangle.Width - rect.Right;
rect.Bottom = richTextBox1.DisplayRectangle.Height - rect.Bottom;
return rect;
}
set
{
Rect rect;
rect.Left = richTextBox1.ClientRectangle.Left + value.Left;
rect.Top = richTextBox1.ClientRectangle.Top + value.Top;
rect.Right = richTextBox1.ClientRectangle.Right - value.Right;
rect.Bottom = richTextBox1.ClientRectangle.Bottom - value.Bottom; SendMessage(richTextBox1.Handle, EM_SETRECT, IntPtr.Zero, ref rect);
} } public int LeftMargin
{
get
{
return RichTextBoxMargin.Left;
}
set
{
Rect rect1;
rect1 = RichTextBoxMargin; Rect rect;
rect.Left = value;
rect.Top = rect1.Top;
rect.Right = rect1.Right;
rect.Bottom = rect1.Bottom; RichTextBoxMargin = rect;
}
} public int RightMargin
{
get
{
return RichTextBoxMargin.Right;
}
set
{
Rect rect1;
rect1 = RichTextBoxMargin; Rect rect;
rect.Left = rect1.Left;
rect.Top = rect1.Top;
rect.Right = value;
rect.Bottom = rect1.Bottom; RichTextBoxMargin = rect;
}
} public int TopMargin
{
get
{
return RichTextBoxMargin.Top;
}
set
{
Rect rect1;
rect1 = RichTextBoxMargin; Rect rect;
rect.Left = rect1.Left;
rect.Top = value;
rect.Right = rect1.Right;
rect.Bottom = rect1.Bottom; RichTextBoxMargin = rect;
}
} public int BottomMargin
{
get
{
return RichTextBoxMargin.Bottom;
}
set
{
Rect rect1;
rect1 = RichTextBoxMargin; Rect rect;
rect.Left = rect1.Left;
rect.Top = rect1.Top;
rect.Right = rect1.Right;
rect.Bottom = value;
RichTextBoxMargin = rect;
}
} }
}
CustomRichTextBox.cs
使用
private void button1_Click(object sender, EventArgs e)
{
customRichTextBox1.LeftMargin = ;
customRichTextBox1.TopMargin = ;
customRichTextBox1.RightMargin = ;
customRichTextBox1.BottomMargin = ;
} private void button2_Click(object sender, EventArgs e)
{
Text = string.Format("Left={0} Right={1} Top={2} Bottom={3}",
customRichTextBox1.LeftMargin,
customRichTextBox1.TopMargin,
customRichTextBox1.RightMargin,
customRichTextBox1.BottomMargin);
}
C# 如何设置 richTextBoxr的边距的更多相关文章
- iOS 设置UILabel 的内边距
iOS 设置UILabel 的内边距 - (void)drawTextInRect:(CGRect)rect { UIEdgeInsets insets = {, , , }; [super draw ...
- Java 设置Word页边距、页面大小、页面方向、页面边框
本文将通过Java示例介绍如何设置Word页边距(包括上.下.左.右).页面大小(可设置Letter/A3/A4/A5/A6/B4/B5/B6/Envelop DL/Half Letter/Lette ...
- Epplus 设置excel 页边距 及多文件合并
1:使用epplus合并多个excel文件到同一excel的不同sheet页中 private static bool MergeExcel(string _stFilePath, List<s ...
- label_设置行距、字距及计算含有行间距的label高度
// // ViewController.m // CNBlogs // // Created by PXJ on 16/5/27. // Copyright © 2016年 PXJ. All ...
- 设置textfield 文字左边距
默认情况下,当向textField输入文字时,文字会紧贴在textField左边框上.我们可以通过设置textField的leftView,设置一个只有宽度的leftView.这样还不够,因为默认le ...
- POI设置Word页边距
参考资料:http://stackoverflow.com/questions/17787176/spacing-and-margin-settings-in-word-document-using- ...
- textField设置输入文字距左边的距离
1.设置tetxField的内边距 [self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"paddingTop&q ...
- [iOS]UIButton内、外边距设置
- (void)viewDidLoad { [super viewDidLoad]; /* UIButton设置对应的边距image跟title的边距属性 ...
- 探究负边距(negative margin)原理
W3C规范在介绍margin时有这样一句话: Negative values for margin properties are allowed, but there may be implement ...
随机推荐
- Eclipse中的add jars和add external jars有什么区别(转载)
转载自:http://blog.csdn.net/yasi_xi/article/details/12772457 add jars和add external jars有什么区别? add ext ...
- 【面试】蘑菇街产品运营二面&结果
2015-08-25 今天下午大概三点半接到了杭州的电话,是蘑菇街的面试官,面试官一开始就说我们简单做个15分钟的面试吧.首先,让我做一个与产品经历相关的自我介绍,我说了自己的产品实习和两个产品比赛经 ...
- Ajax编程相对路径与绝对路径
http://www.worlduc.com/blog2012.aspx?bid=16946309 ajax同一域名调用采用相对路径 var url = 'QuerySingleDataByField ...
- bzoj 3784: 树上的路径 堆维护第k大
3784: 树上的路径 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 88 Solved: 27[Submit][Status][Discuss] ...
- Ecmall系统自带的分页功能
在Ecmall的二次开发中,分页是必不可少的.这个系统已经自带了分页功能,下面来看看如何使用这个分页. 下面是一个自定义的类,用于查看订单的详细情况.关键在于get_order_data()这个方法, ...
- 移动应用产品开发-android开发(三)
历时一个多月的时间,这款APP算是开发完成了,最近在测试完善中,比较空闲好好总结下. 之前两次已经提到开发过程中的主要的知识点,这次主要总结下解决问题方法,http请求和安全. 首先讲下解决问题的方法 ...
- 李洪强漫谈iOS开发[C语言-028]-逗号表达式
- oracle的sqlnet.ora , tnsnames.ora , Listener.ora 文件的作用(转)
oracle网络配置三个配置文件 listener.ora.sqlnet.ora.tnsnames.ora ,都是放在$ORACLE_HOME/network/admin目录下.1. sqlnet.o ...
- WordPress Sharebar ‘page’参数跨站脚本漏洞
漏洞名称: WordPress Sharebar ‘page’参数跨站脚本漏洞 CNNVD编号: CNNVD-201309-468 发布时间: 2013-09-26 更新时间: 2013-09-26 ...
- Android 全屏显示-隐藏Navigation Bar
Sumsung Galaxy Nexus 屏幕分辨率为 1280X 720,但通常的应用都会显示Navigation Bar(Back 键,Home 键等),如下图所示: 但我注意到Youtube应用 ...