哪位兄弟可知道怎么重绘treeview的滚动条?

Harvey_zhang 2008-01-21 01:29:47
滚动条漂亮一点,类似QQ
...全文
613 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2008-01-28
  • 打赏
  • 举报
回复
其实MSDN上有一个画滚动条的例子,如果你愿意,你完全可以不使用示例中的ScrollBarRenderer而自己来绘制:

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace ScrollBarRendererSample
{
class Form1 : Form
{
public Form1()
: base()
{
this.Size = new Size(500, 500);

CustomScrollBar Bar1 = new CustomScrollBar();
Bar1.Location = new Point(50, 100);
Bar1.Size = new Size(200, 20);

Controls.Add(Bar1);
}

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}

public class CustomScrollBar : Control
{
private Rectangle clickedBarRectangle;
private Rectangle thumbRectangle;
private Rectangle leftArrowRectangle;
private Rectangle rightArrowRectangle;
private bool leftArrowClicked = false;
private bool rightArrowClicked = false;
private bool leftBarClicked = false;
private bool rightBarClicked = false;
private bool thumbClicked = false;
private ScrollBarState thumbState = ScrollBarState.Normal;
private ScrollBarArrowButtonState leftButtonState =
ScrollBarArrowButtonState.LeftNormal;
private ScrollBarArrowButtonState rightButtonState =
ScrollBarArrowButtonState.RightNormal;

private int thumbWidth = 15;
private int arrowWidth = 17;
private int thumbRightLimitRight = 0;
private int thumbRightLimitLeft = 0;
private int thumbLeftLimit = 0;
private int thumbPosition = 0;
private int trackPosition = 0;
private Timer progressTimer = new Timer();

public CustomScrollBar()
: base()
{
this.Location = new Point(10, 10);
this.Width = 200;
this.Height = 20;
this.DoubleBuffered = true;

SetUpScrollBar();
progressTimer.Interval = 20;
progressTimer.Tick += new EventHandler(progressTimer_Tick);
}

private void SetUpScrollBar()
{
clickedBarRectangle = ClientRectangle;
thumbRectangle = new Rectangle(
ClientRectangle.X + ClientRectangle.Width / 2,
ClientRectangle.Y, thumbWidth,
ClientRectangle.Height);
leftArrowRectangle = new Rectangle(
ClientRectangle.X, ClientRectangle.Y,
arrowWidth, ClientRectangle.Height);
rightArrowRectangle = new Rectangle(
ClientRectangle.Right - arrowWidth,
ClientRectangle.Y, arrowWidth,
ClientRectangle.Height);

thumbPosition = thumbWidth / 2;

thumbRightLimitRight = ClientRectangle.Right - arrowWidth;

thumbRightLimitLeft = thumbRightLimitRight - thumbWidth;

thumbLeftLimit = ClientRectangle.X + arrowWidth;
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

if (!ScrollBarRenderer.IsSupported)
{
this.Parent.Text = "CustomScrollBar Disabled";
return;
}

this.Parent.Text = "CustomScrollBar Enabled";

ScrollBarRenderer.DrawRightHorizontalTrack(e.Graphics,
ClientRectangle, ScrollBarState.Normal);

ScrollBarRenderer.DrawHorizontalThumb(e.Graphics,
thumbRectangle, thumbState);
ScrollBarRenderer.DrawHorizontalThumbGrip(e.Graphics,
thumbRectangle, thumbState);

ScrollBarRenderer.DrawArrowButton(e.Graphics,
leftArrowRectangle, leftButtonState);
ScrollBarRenderer.DrawArrowButton(e.Graphics,
rightArrowRectangle, rightButtonState);

if (leftBarClicked)
{
clickedBarRectangle.X = thumbLeftLimit;
clickedBarRectangle.Width = thumbRectangle.X - thumbLeftLimit;
ScrollBarRenderer.DrawLeftHorizontalTrack(e.Graphics,
clickedBarRectangle, ScrollBarState.Pressed);
}

else if (rightBarClicked)
{
clickedBarRectangle.X =
thumbRectangle.X + thumbRectangle.Width;
clickedBarRectangle.Width =
thumbRightLimitRight - clickedBarRectangle.X;
ScrollBarRenderer.DrawRightHorizontalTrack(e.Graphics,
clickedBarRectangle, ScrollBarState.Pressed);
}
}

protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);

if (!ScrollBarRenderer.IsSupported)
return;

if (thumbRectangle.Contains(e.Location))
{
thumbClicked = true;
thumbPosition = e.Location.X - thumbRectangle.X;
thumbState = ScrollBarState.Pressed;
}

else if (leftArrowRectangle.Contains(e.Location))
{
leftArrowClicked = true;
leftButtonState = ScrollBarArrowButtonState.LeftPressed;
progressTimer.Start();
}

else if (rightArrowRectangle.Contains(e.Location))
{
rightArrowClicked = true;
rightButtonState = ScrollBarArrowButtonState.RightPressed;
progressTimer.Start();
}
else
{
trackPosition = e.Location.X;

if (e.Location.X < this.thumbRectangle.X)
{
leftBarClicked = true;
}
else
{
rightBarClicked = true;
}
progressTimer.Start();
}

Invalidate();
}

protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);

if (!ScrollBarRenderer.IsSupported)
return;

if (thumbClicked)
{
thumbClicked = false;
thumbState = ScrollBarState.Normal;

if (e.Location.X > (thumbLeftLimit + thumbPosition) &&
e.Location.X < (thumbRightLimitLeft + thumbPosition))
{
thumbRectangle.X = e.Location.X - thumbPosition;
thumbClicked = false;
}
}
else if (leftArrowClicked)
{
leftArrowClicked = false;
leftButtonState = ScrollBarArrowButtonState.LeftNormal;
progressTimer.Stop();
}

else if (rightArrowClicked)
{
rightArrowClicked = false;
rightButtonState = ScrollBarArrowButtonState.RightNormal;
progressTimer.Stop();
}

else if (leftBarClicked)
{
leftBarClicked = false;
progressTimer.Stop();
}

else if (rightBarClicked)
{
rightBarClicked = false;
progressTimer.Stop();
}

Invalidate();
}

protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);

if (!ScrollBarRenderer.IsSupported)
return;

if (thumbClicked)
{
if (e.Location.X <= (thumbLeftLimit + thumbPosition))
{
thumbRectangle.X = thumbLeftLimit;
}

else if (e.Location.X >= (thumbRightLimitLeft + thumbPosition))
{
thumbRectangle.X = thumbRightLimitLeft;
}

else
{
thumbRectangle.X = e.Location.X - thumbPosition;
}

Invalidate();
}
}

protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
SetUpScrollBar();
}

private void progressTimer_Tick(object sender, EventArgs myEventArgs)
{
if (!ScrollBarRenderer.IsSupported)
return;

if (rightArrowClicked && thumbRectangle.X < thumbRightLimitLeft)
{
thumbRectangle.X++;
}
else if (leftArrowClicked && thumbRectangle.X > thumbLeftLimit)
{
thumbRectangle.X--;
}

else if (rightBarClicked &&
thumbRectangle.X < thumbRightLimitLeft &&
thumbRectangle.X + thumbRectangle.Width < trackPosition)
{
thumbRectangle.X += 3;
}
else if (leftBarClicked &&
thumbRectangle.X > thumbLeftLimit &&
thumbRectangle.X > trackPosition)
{
thumbRectangle.X -= 3;
}

Invalidate();
}
}
}}
ouhou 2008-01-27
  • 打赏
  • 举报
回复
jf.haha
Harvey_zhang 2008-01-27
  • 打赏
  • 举报
回复
自己顶
benyouyong 2008-01-23
  • 打赏
  • 举报
回复
VB鼠标滚动事件,没有样式。

Private Const PM_REMOVE = &H1
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg ByVal hWnd As Long ByVal wMsgFilterMin As Long ByVal wMsgFilterMax As Long ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Const WM_MOUSEWHEEL = 522

Private Sub ProcessMessages()
Dim Message As Msg
Do While Not bCancel
WaitMessage 'Wait For message and...
If PeekMessage(Message Me.hWnd WM_MOUSEWHEEL WM_MOUSEWHEEL PM_REMOVE) Then '...when the mousewheel is used...
If Message.wParam < 0 Then '...scroll up...
Me.Top = Me.Top + 240
Else '... or scroll down
Me.Top = Me.Top - 240
End If
End If
DoEvents
Loop
End Sub

Private Sub Form_Load()
Me.AutoRedraw = True
Me.Print "Please use now mouse wheel to move this form."
Me.Show
ProcessMessages
End Sub

Private Sub Form_Unload(Cancel As Integer)
bCancel = True
End Sub
Harvey_zhang 2008-01-23
  • 打赏
  • 举报
回复
LS说的及是,滚动条要自己写,这样很麻烦,谁知道有免费的换肤控件么?
ShiningstarHu 2008-01-23
  • 打赏
  • 举报
回复

用最新的WPF来做。非常容易实现。
Harvey_zhang 2008-01-23
  • 打赏
  • 举报
回复
谢谢,改变滚动条样式怎么做,不是系统的滚动条
FollowCN 2008-01-22
  • 打赏
  • 举报
回复
等待老大出现呀
Harvey_zhang 2008-01-22
  • 打赏
  • 举报
回复
zijiding
shinaterry 2008-01-22
  • 打赏
  • 举报
回复
自己定控件, 实现滚动条的功能, 替换系统默认的比较实际...

处理非客户区域很痛苦的...

-_-!!!
  • 打赏
  • 举报
回复
没试出来
wdzr_826 2008-01-22
  • 打赏
  • 举报
回复
winform飘过
Harvey_zhang 2008-01-22
  • 打赏
  • 举报
回复
老大救命瓦
sx_rubbish 2008-01-21
  • 打赏
  • 举报
回复
up~
Harvey_zhang 2008-01-21
  • 打赏
  • 举报
回复
忘记说了,c/s的treeview
chuxue1342 2008-01-21
  • 打赏
  • 举报
回复
滚动条可以自己设置CSS样式:
html {
scrollbar-face-color:#E0FFFF;
scrollbar-highlight-color:#E0FFFF;
scrollbar-3dlight-color:#20B2AA;
scrollbar-darkshadow-color:#000099;
scrollbar-Shadow-color:#5F9EA0;
scrollbar-arrow-color:#0000FF;
scrollbar-track-color:#ADD8E6;
}
你自己多试试得到你想要的效果!
Harvey_zhang 2008-01-21
  • 打赏
  • 举报
回复
up就有分,急用
zmaini1420 2008-01-21
  • 打赏
  • 举报
回复
up!~
Harvey_zhang 2008-01-21
  • 打赏
  • 举报
回复
我看一下,谢谢
haiwangstar 2008-01-21
  • 打赏
  • 举报
回复
你可以参考一下这个。

http://www.setoutsoft.cn/skinscroll.htm

看了应该就会做了,是用很曲折的办法实现。
加载更多回复(4)

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧