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 ...
随机推荐
- CALayer -- 备忘
CALayer layer是层,每个view上都会最少有一个layer,view上的可视化内容其实都是层. CALayer展示实例 let customView = UIView(frame: CGR ...
- swift 与 OC 混合编程
原文地址:http://www.cocoachina.com/swift/20150608/12025.html 一.解决问题 Swift项目需要使用封装好的Objective-c组件.第三方类库,苹 ...
- ASP.NET State Service服务
ASP.NET State Service服务是用来管理 Session 的,正常来说,Session 位于IIS进程中(其实可以理解成在服务器的内存中),当IIS重启或程序池回收会自动清空Sessi ...
- python is == 的区别
要点: is 判断是否是同一个对象.是通过id来判断的 == 是通过值来判断的 为了提高内存利用率对一些简单的对象,如一些数值较小的int对象,python采用重用对象内存的方法 例如指向 ...
- TiDB:支持 MySQL 协议的分布式数据库解决方案
[编者按]TiDB 是国内 PingCAP 团队开发的一个分布式 SQL 数据库.其灵感来自于 Google 的 F1,TiDB 支持包括传统 RDBMS 和 NoSQL 的特性.在国内 ITOM 管 ...
- Java 声明和访问控制(一) 数组的声明 private可以修饰类吗
数组的声明: int []a[] = new int[4][];//是正确的 int[] array = new int[2]{1,2};//是错误的 数组的长度是不可改变的,不能通过任何方式改变大小 ...
- windows进程中的内存结构(好多API,而且VC最聪明)
在阅读本文之前,如果你连堆栈是什么多不知道的话,请先阅读文章后面的基础知识. 接触过编程的人都知道,高级语言都能通过变量名来访问内存中的数据.那么这些变量在内存中是如何存放的呢?程序又是如何使用这 ...
- bzoj1023
研究了一下仙人掌首先,仙人掌虽然不是树,但却有很强的树的既视感如果把每个环都看做一个点,那么他就是一棵树当然这不能直接缩环,因为环和环可以有一个交点如果是树,求直径都会做,令f[i]表示i到子树的最长 ...
- 转自 x_x的百度空间
空华人生 by 淡漠的心情 昨天,又昨天. 今天,又今天. 明天,又明天. 日历渐渐稀薄,忽然发现,那是时间的痕迹. 似乎,总是在麻木的等待. 何时,才能历尽. 再算算,我又还有多少天 ...
- 【转】Valid signing identity not found解决办法(原有IDP私钥丢失)及Certificate、App ID、Devices、Provisioning Profiles之间区别--不错
原文网址:http://blog.csdn.net/mad1989/article/details/8699147 前言: 刚刚把mini换成了macbookair,之前一直在mini上进行开发,到换 ...