C 自定義重繪TabControl

2022-02-11 07:18:35 字數 4737 閱讀 9144

using

system.drawing;

using

system.windows.forms;

using

system.drawing.drawing2d;

using

system.runtime.interopservices;

using

system;

using

system.drawing.text;

using

system.componentmodel;

namespace

controlexs.controlexs.ctabcontrol

private

void

setstyles()

private color _backcolor = color.fromargb(23, 169, 254

); [browsable(

true

)] [editorbrowsable(editorbrowsablestate.always)]

[defaultvalue(

typeof(color), "

23, 169, 254")]

public

override

color backcolor

set }

private color _bordercolor = color.fromargb(23, 169, 254

); [defaultvalue(

typeof(color), "

23, 169, 254")]

[description(

"tabcontorl邊框色")]

public

color bordercolor

set }

private color _headselectedbackcolor = color.fromargb(23, 169, 254

); [defaultvalue(

typeof(color), "

23, 169, 254")]

[description(

"tabpage頭部選中後的背景顏色")]

public

color headselectedbackcolor

set

}private color _headselectedbordercolor = color.fromargb(23, 169, 254

); [defaultvalue(

typeof(color), "

23, 169, 254")]

[description(

"tabpage頭部選中後的邊框顏色")]

public

color headselectedbordercolor

set

}private color _headerbackcolor = color.fromargb(23, 169, 254

); [defaultvalue(

typeof(color), "

23, 169, 254")]

[description(

"tabpage頭部預設邊框顏色")]

public

color headerbackcolor

set

}protected

override

void

onpaintbackground(painteventargs pevent)

else

}//////

tabcontorl 背景色設定

/// ///

///protected

void

painttransparentbackground(graphics g, rectangle cliprect)

finally}}

else

}protected

override

void

onpaint(painteventargs e)

private

void

paintallthetabs(system.windows.forms.painteventargs e)}}

private

void painttab(system.windows.forms.painteventargs e, int

index)

//////

設定選項卡頭部顏色

/// ///

//////

private

void painttabbackground(system.drawing.graphics graph, int

index, system.drawing.drawing2d.graphicspath path)

graph.fillpath(buttonbrush, path);

buttonbrush.dispose();

}//////

設定選項卡頭部邊框色

/// ///

//////

private

void painttabborder(system.drawing.graphics graph, int

index, system.drawing.drawing2d.graphicspath path)

graph.drawpath(borderpen, path);

borderpen.dispose();

}private

void painttabimage(system.drawing.graphics g, int

index)

else

if (this.tabpages[index].imagekey.trim().length > 0 && this.imagelist != null

)

if (tabimage != null

)

}private

void painttabtext(system.drawing.graphics graph, int

index)

string tabtext = this

.tabpages[index].text;

system.drawing.stringformat format = new

system.drawing.stringformat();

format.alignment =stringalignment.near;

format.linealignment =stringalignment.center;

format.trimming =stringtrimming.ellipsischaracter;

brush forebrush = null

;

if (this.tabpages[index].enabled == false

)

else

font tabfont = this

.font;

if (index == this

.selectedindex)

} graph.drawstring(tabtext, tabfont, forebrush, rect2, format);

}//////

設定 tabpage 內容頁邊框色

/// ///

private

void

paintthetabpageborder(system.windows.forms.painteventargs e)

}//////

// tabpage 頁頭部間隔色

/// ///

private

void

painttheselectedtab(system.windows.forms.painteventargs e)

}private graphicspath getpath(int

index)

if (index == 0

)

else

else

}return

path;

}[dllimport(

"user32.dll")]

private

static

extern intptr sendmessage(intptr hwnd, int

msg, intptr wparam, intptr lparam);

private

const

int wm_setfont = 0x30

;

private

const

int wm_fontchange = 0x1d

;

protected

override

void

oncreatecontrol()

protected

override

void

onfontchanged(eventargs e)

}}

自定義控制項重繪沒有效果

問題描述 public class myviewactivity extends actionbaractivity 觸筆事件 public boolean ontouchevent motionevent event 按鍵按下事件 public boolean onkeydown int keyc...

Linq去重(自定義字段)

業務場景,接受乙個datatable 根需求需要按照品號去重 業務場景 明細表存在多筆相同品號 在這樣的場景下不能簡單的使用如下寫法去重 var list tempdatatable.asenumerable where p p total inv qty todecimal p total iss...

C 自定義控制項和自定義事件

今天在專案開發的過程中,因為好幾個頁面都要用到同乙個分類控制項,就想著把它做成乙個自定義控制項,然後隨託隨用。在網上找了些列子,自定義控制項的寫法不用多說,主要說一下,如何將控制項的事件,封裝到自己定義的控制項的自定義事件裡面。這裡同時也當作對自定義事件的乙個複習吧。首先控制項是乙個由treelis...