如何触发轨迹栏的OnValueChanged事件 [英] how to trigger the trackbar's OnValueChanged event
本文介绍了如何触发轨迹栏的OnValueChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我绘制了trackbar组件并将其命名为cumstomtrackbar,它继承自trackbar类。
但我发现customtrackbar无法触发OnValueChanged事件,如何触发它?
一些相关的代码如下:
I drawed trackbar component and named it as cumstomtrackbar,it inherit from trackbar class.
But I find that the customtrackbar can't tigger OnValueChanged event,how to trigger it ?
some releated code as below:
public class CustomTrackBar:System.Windows.Forms.TrackBar
{
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM.WM_PAINT:
if (true)
{
PAINTSTRUCT ps = new PAINTSTRUCT();
BeginPaint(m.HWnd, ref ps);
DrawTrackBar(m.HWnd);
ValidateRect(m.HWnd, ref ps.rcPaint);
EndPaint(m.HWnd, ref ps);
}
else
{
base.WndProc(ref m);
}
break;
default:
base.WndProc(ref m);
break;
}
}
}
推荐答案
首先:为什么要覆盖WndProc?我建议覆盖OnPaint方法。
然后:您的自定义控件应该具有像Base-Control这样的Value-Property。现在......如果您的值发生变化(将其与last_Value - 另一个变量 - 可能在您的Value-Property的Setter中进行比较),则调用OnValueChanged-Method。此方法将引发事件。
At first : why do you override the WndProc ? I would suggest to override the OnPaint-method.
Then : your customized Control should have a Value-Property like the Base-Control. Now ... if your value changes (compare it with the last_Value - another variable - perhaps in the Setter of your Value-Property) you call the OnValueChanged-Method. This Method will raise the Event.
这篇关于如何触发轨迹栏的OnValueChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文