C# WinForm中Panel實(shí)現(xiàn)用鼠標(biāo)操作滾動條的實(shí)例方法
方法如下:
在窗體的Load事件注冊滾動事件,并增加對應(yīng)的方法
private void FormSample_Load(object sender, EventArgs e)
{
//注冊事件
this.MouseWheel += new MouseEventHandler(FormSample_MouseWheel);
}
/// <summary>
/// 滾動方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void FormSample_MouseWheel(object sender, MouseEventArgs e)
{
//獲取光標(biāo)位置
Point mousePoint = new Point(e.X,e.Y);
//換算成相對本窗體的位置
mousePoint.Offset(this.Location.X, this.Location.Y);
//判斷是否在panel內(nèi)
if (pnlDownload.RectangleToScreen(
pnlDownload.DisplayRectangle).Contains(mousePoint))
{
//滾動
pnlDownload.AutoScrollPosition = new Point(
, pnlDownload.VerticalScroll.Value - e.Delta);
}
}
相關(guān)文章
C#實(shí)現(xiàn)自定義windows系統(tǒng)日志的方法
這篇文章主要介紹了C#實(shí)現(xiàn)自定義windows系統(tǒng)日志的方法,涉及C#針對windows系統(tǒng)日志的創(chuàng)建、讀寫及刪除技巧,非常具有實(shí)用價值,需要的朋友可以參考下2015-08-08C#使用DataSet Datatable更新數(shù)據(jù)庫的三種實(shí)現(xiàn)方法
這篇文章主要介紹了C#使用DataSet Datatable更新數(shù)據(jù)庫的三種實(shí)現(xiàn)方法,需要的朋友可以參考下2014-08-08C#通過創(chuàng)建Windows服務(wù)啟動程序的方法詳解
這篇文章主要介紹了C#通過創(chuàng)建Windows服務(wù)啟動程序的方法,較為詳細(xì)的分析了C#創(chuàng)建Windows服務(wù)應(yīng)用程序的步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-06-06