話說分頁這玩意在開發中可是相當的常見。網上到處都是分頁的資料。可是在winform中要做到分頁顯示文字內容就沒有那麼容易。而且不能使用一些可以分頁的控制項,比較dategridview等。只好在已有的**基礎上開發了乙個具備分頁功能,並且可以改變行間距的label。
**寫的比較長,可以拷貝下來直接使用,體驗下。
using system;
using system.componentmodel;
using system.collections.generic;
using system.diagnostics;
using system.text;
using system.drawing;
using system.text.regularexpressions;
public partial class labelex : system.windows.forms.label
set}
[descriptionattribute("label在容器下端顯示不了時附加高度")]
public int attachheight
set}
[descriptionattribute("label所在的容器的高度")]
public int containerheight
set}
[descriptionattribute("獲取或設定行距")]
public int linedistance
set}
[descriptionattribute("頁碼,在翻頁模式下有用")]
public int pageno
set}
}public labelex()
: base()
void labelex_fontchanged(object sender, eventargs e)
void labelex_sizechanged(object sender, eventargs e)
public labelex(icontainer container)
[descriptionattribute("頁面高度,在翻頁模式下有用")]
public int pageheight
set}
[descriptionattribute("呈現模式")]
public dispmode displaymode
set
}[descriptionattribute("獲取文字高度")]
public int fheight
}[descriptionattribute("獲取行高")]
public int lineheight
}public int sectionheight
}[descriptionattribute("設定或獲取段落間距")]
public int secdistance
set
}public new int height
set}
public override string text
setelse}}
public bool isend
}protected void changed(font ft, int iwidth, string value)
nrline = value.split(new string[1] , stringsplitoptions.removeemptyentries);
section = nrline.length;
nrlinepos = new string[section];
sizef sf1, sf2;
string temps, tempt;
string drawstring;
int tempos, ipos;
for (int i = 0; i < section; i++)
drawstring = nrline[i];
nrlinepos[i] = "";
while (drawstring.length > searchpos)
}if (!isfind)
}ipos += drawstring.length;
nrlinepos[i] += "," + ipos.tostring();
iheight++;
//templine = (int)(sf1.width - 1) / this.width + 1;
//iheight += templine;}}
if (dm == dispmode.none)
if (this.containerheight == 0)
else
string strlinepos = nrlinepos[i].trimstart(',');
ilinenum = strlinepos.split(',').length;
for (int j = 0; j < ilinenum; j++)
//if (this.top < 0)
//int reltop = itop % containerheight;
int tempheight = 0;
if (j == ilinenum - 1)
else
if (tempheight > containerheight)
//tmpheight += tempheight - containerheight + 2;
}if (j == ilinenum - 1)
else}}
this.height = tmpheight;
}//add by kevin gao 20110511 --------------end}}
protected override void onpaint(system.windows.forms.painteventargs e)
first = 0;
substr = nrline[i];
if (nrlinepos[i] != null) tmpstr = nrlinepos[i].trimstart(',');
midstr = substr.substring(first);
if (tmpstr != "")
else
int reltop = itop % containerheight;
int tempheight = 0;
if (j == idxs.length - 1)
else
if (tempheight > containerheight)
else
}else
}//add by kevin gao 20110511 ---end
drawfont, drawbrush, x, convert.toint16(htheight), drawformat);
}else
return;
}prelinestr = midstr;
ispagestart = true;
htheight = 0;
}else
ispagestart = false;
e.graphics.drawstring(midstr, drawfont, drawbrush, x, convert.toint16(htheight), drawformat);
}if (i == section - 1 && j == idxs.length - 1)}}
if (j == idxs.length - 1)
else
first = idx;}}
}}///
/// 清除文字中的html標籤
///
/// 要替換的標籤正規表示式
/// 替換為的內容
/// 要替換的內容
///
private string zxj_replacehtml(string patrn, string strrep, string content)
regex rgex = new regex(patrn, regexoptions.ignorecase);
string strtxt = rgex.replace(content, strrep);
return strtxt;
}///
/// 清除文字中html的標籤
///
///
///
private string clearhtml(string content)
}///
/// 顯示模式,分為全顯示和分頁顯示兩種
///
public enum dispmode
能夠分頁顯示的Label控制項
話說分頁這玩意在開發中可是相當的常見。網上到處都是分頁的資料。可是在winform中要做到分頁顯示文字內容就沒有那麼容易。而且不能使用一些可以分頁的控制項,比較dategridview等。只好在已有的 基礎上開發了乙個具備分頁功能,並且可以改變行間距的label。寫的比較長,可以拷貝下來直接使用,體...
使用label控制項實現資料分頁
pageddatasource pg new pageddatasource pg.datasource ds.tables 0 defaultview pg.allowpaging true pg.pagesize 6 int currpage if request.querystring pag...
GridView控制項分頁顯示資料
using system using system.collections.generic using system.linq using system.web using system.web.ui using system.web.ui.webcontrols using system.conf...