.NET 解决TabControl 页里面多余边距问题经验分享
程序员文章站
2024-03-07 08:58:20
以下是解决方法: 1.直接新建一个类,继承tabcontrol,然后 override displayrectangle 方法: 复制代码 代码如下: ///
以下是解决方法:
1.直接新建一个类,继承tabcontrol,然后 override displayrectangle 方法:
/// <summary>
/// 解决系统tabcontrol多余边距问题
/// </summary>
public class fulltabcontrol : tabcontrol {
public override rectangle displayrectangle {
get {
rectangle rect = base.displayrectangle;
return new rectangle(rect.left - 4, rect.top - 4, rect.width + 8, rect.height + 7);
}
}
}
以后用 fulltabcontrol 就行。(这种方法简单)
2.参见以下网址(vb.net)代码:
http://www.blueshop.com.tw/board/fum20050124191756kkc/brd201112281018075b8.html
c# 代码为:
public class fulltabcontrol : nativewindow {
static int tcm_first = 0x1300;
static int tcm_adjustrect = (tcm_first + 40);
struct rect{
public int left, top, right, bottom;
}
protected override void wndproc(ref message m) {
if (m.msg == tcm_adjustrect) {
rect rc = (rect)m.getlparam(typeof(rect));
rc.left -= 4;
rc.right += 3;
rc.top -= 4;
rc.bottom += 3;
marshal.structuretoptr(rc, m.lparam, true);
}
base.wndproc(ref m);
}
}
调用方法:new fulltabcontrol().assignhandle(tabcontrol1.handle);// tabcontrol1为窗口上tabcontrol控件的名称
版权声明作者:夏荣全
邮箱:lyout(at)163.com
1.直接新建一个类,继承tabcontrol,然后 override displayrectangle 方法:
复制代码 代码如下:
/// <summary>
/// 解决系统tabcontrol多余边距问题
/// </summary>
public class fulltabcontrol : tabcontrol {
public override rectangle displayrectangle {
get {
rectangle rect = base.displayrectangle;
return new rectangle(rect.left - 4, rect.top - 4, rect.width + 8, rect.height + 7);
}
}
}
以后用 fulltabcontrol 就行。(这种方法简单)
2.参见以下网址(vb.net)代码:
http://www.blueshop.com.tw/board/fum20050124191756kkc/brd201112281018075b8.html
c# 代码为:
复制代码 代码如下:
public class fulltabcontrol : nativewindow {
static int tcm_first = 0x1300;
static int tcm_adjustrect = (tcm_first + 40);
struct rect{
public int left, top, right, bottom;
}
protected override void wndproc(ref message m) {
if (m.msg == tcm_adjustrect) {
rect rc = (rect)m.getlparam(typeof(rect));
rc.left -= 4;
rc.right += 3;
rc.top -= 4;
rc.bottom += 3;
marshal.structuretoptr(rc, m.lparam, true);
}
base.wndproc(ref m);
}
}
调用方法:new fulltabcontrol().assignhandle(tabcontrol1.handle);// tabcontrol1为窗口上tabcontrol控件的名称
版权声明作者:夏荣全
邮箱:lyout(at)163.com