作成日: 2018/02/14 最終更新日: 2018/02/14
文書種別
使用方法
詳細
C1GanttViewのチャートビュー上でタスクを選択し、[ctrl]+マウススクロールすると、タスクがズームされタイムスケールの区分が変更されます。
この動作を抑止したい場合、IMessageFilterインターフェースを実装したクラスを作成し、マウススクロールのメッセージをキャンセルします。
サンプルコード
◎サンプルコード(VB)
◎サンプルコード(C#)
この動作を抑止したい場合、IMessageFilterインターフェースを実装したクラスを作成し、マウススクロールのメッセージをキャンセルします。
サンプルコード
◎サンプルコード(VB)
Dim _filter As IMessageFilter
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim task1 As C1.Win.C1GanttView.Task = C1GanttView1.Tasks(0)
task1.Name = "Task1"
task1.Start = DateTime.Today
task1.Finish = DateTime.Today.AddDays(3)
End Sub
Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
MyBase.OnHandleCreated(e)
_filter = New MessageFilter(C1GanttView1.Handle)
Application.AddMessageFilter(_filter)
End Sub
Protected Overrides Sub OnHandleDestroyed(ByVal e As EventArgs)
MyBase.OnHandleDestroyed(e)
Application.RemoveMessageFilter(_filter)
End Sub
Class MessageFilter
Implements IMessageFilter
Private _handle As IntPtr
Public Sub New(ByVal handle As IntPtr)
_handle = handle
End Sub
Private Shared Function LOWORD(ByVal ip As IntPtr) As Integer
Return CInt((CShort((ip.ToInt64() And 65535))))
End Function
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
If m.Msg = 522 AndAlso (LOWORD(m.WParam) And 8) = 8 Then
Dim ctrl As Control = Control.FromHandle(m.HWnd)
If ctrl Is Nothing Then Return False
While ctrl IsNot Nothing
If ctrl.Handle = _handle Then Return True
ctrl = ctrl.Parent
End While
End If
Return False
End Function
End Class
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim task1 As C1.Win.C1GanttView.Task = C1GanttView1.Tasks(0)
task1.Name = "Task1"
task1.Start = DateTime.Today
task1.Finish = DateTime.Today.AddDays(3)
End Sub
Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
MyBase.OnHandleCreated(e)
_filter = New MessageFilter(C1GanttView1.Handle)
Application.AddMessageFilter(_filter)
End Sub
Protected Overrides Sub OnHandleDestroyed(ByVal e As EventArgs)
MyBase.OnHandleDestroyed(e)
Application.RemoveMessageFilter(_filter)
End Sub
Class MessageFilter
Implements IMessageFilter
Private _handle As IntPtr
Public Sub New(ByVal handle As IntPtr)
_handle = handle
End Sub
Private Shared Function LOWORD(ByVal ip As IntPtr) As Integer
Return CInt((CShort((ip.ToInt64() And 65535))))
End Function
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
If m.Msg = 522 AndAlso (LOWORD(m.WParam) And 8) = 8 Then
Dim ctrl As Control = Control.FromHandle(m.HWnd)
If ctrl Is Nothing Then Return False
While ctrl IsNot Nothing
If ctrl.Handle = _handle Then Return True
ctrl = ctrl.Parent
End While
End If
Return False
End Function
End Class
◎サンプルコード(C#)
IMessageFilter _filter;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
C1.Win.C1GanttView.Task task1 = c1GanttView1.Tasks[0];
task1.Name = "Task1";
task1.Start = DateTime.Today;
task1.Finish = DateTime.Today.AddDays(3);
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
Application.AddMessageFilter(_filter = new MessageFilter(c1GanttView1.Handle));
}
protected override void OnHandleDestroyed(EventArgs e)
{
base.OnHandleDestroyed(e);
Application.RemoveMessageFilter(_filter);
}
class MessageFilter : IMessageFilter
{
IntPtr _handle;
public MessageFilter(IntPtr handle)
{
_handle = handle;
}
static int LOWORD(IntPtr ip)
{
return (int)((short)(ip.ToInt64() & 0xffff));
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x020A && (LOWORD(m.WParam) & 0x0008) == 0x0008) //WM_MOUSEWHEEL, MK_CONTROL
{
Control ctrl = Control.FromHandle(m.HWnd);
if (ctrl == null)
return false;
while (ctrl != null)
{
if (ctrl.Handle == _handle)
return true;
ctrl = ctrl.Parent;
}
}
return false;
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
C1.Win.C1GanttView.Task task1 = c1GanttView1.Tasks[0];
task1.Name = "Task1";
task1.Start = DateTime.Today;
task1.Finish = DateTime.Today.AddDays(3);
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
Application.AddMessageFilter(_filter = new MessageFilter(c1GanttView1.Handle));
}
protected override void OnHandleDestroyed(EventArgs e)
{
base.OnHandleDestroyed(e);
Application.RemoveMessageFilter(_filter);
}
class MessageFilter : IMessageFilter
{
IntPtr _handle;
public MessageFilter(IntPtr handle)
{
_handle = handle;
}
static int LOWORD(IntPtr ip)
{
return (int)((short)(ip.ToInt64() & 0xffff));
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x020A && (LOWORD(m.WParam) & 0x0008) == 0x0008) //WM_MOUSEWHEEL, MK_CONTROL
{
Control ctrl = Control.FromHandle(m.HWnd);
if (ctrl == null)
return false;
while (ctrl != null)
{
if (ctrl.Handle == _handle)
return true;
ctrl = ctrl.Parent;
}
}
return false;
}
}
旧文書番号
82525