【问题标题】:Need to create a calendar with drag and drop events. Which control to use?需要创建带有拖放事件的日历。使用哪个控件?
【发布时间】:2015-02-05 01:40:59
【问题描述】:

我正在使用 VB.Net 2012 Express

我需要创建一个包含拖放元素的日历。我会将它链接到数据库,但首先我需要确定使用哪个控件来创建日历显示。

我希望能够通过用鼠标拖动矩形来创建事件。也可以通过拖放事件来移动事件。

我正在尝试使用 tablelayoutpanel (tlp)。我可以通过编程方式创建 tlp,但是当我单击时看不到如何判断鼠标在哪一行或哪一列,因为它只给了我 X 和 Y,而不是 tablelayoutpanel 的行或列。

如何找出鼠标按下时所在的行/列,以及鼠标向上时所在的行/列?还是我完全找错了树?

【问题讨论】:

  • GDI+ 带有鼠标事件
  • 我可以看到如何通过鼠标事件获取 X 和 Y,但看不到行或列?
  • 每一天都是Rectangle,您可以使用Rectangle.Contains(e.x, e.y)检查鼠标点击,您将负责将它们放置在行/列中 - 带有条件的for循环。

标签: vb.net datagridview calendar tablelayoutpanel


【解决方案1】:

感谢 OneFineDay,您让我走上了正确的道路。我有点偏离了方向,但想出了这个并且它有效:

 Private Sub Layout_Calendar_MouseDown(sender As Object, e As MouseEventArgs) Handles Layout_Calendar.MouseDown
    Dim x As Integer
    x = e.X

    Dim y As Integer
    y = e.Y

    Dim Allcolumns() As Integer
    Dim ColumnLocation As Integer
    Dim Column As Integer

    Dim Allrows() As Integer
    Dim RowLocation As Integer
    Dim Row As Integer


    'find column
    Allcolumns = Layout_Calendar.GetColumnWidths()
    ColumnLocation = 0
    Column = 0
    For Each Colwidth In Allcolumns
        ColumnLocation += Colwidth
        If x < ColumnLocation Then
            Exit For
        Else
            Column += 1
        End If
    Next


    Allrows = Layout_Calendar.GetRowHeights()
    RowLocation = 0
    Row = 0
    For Each Rowwidth In Allrows
        RowLocation += Rowwidth
        If y < RowLocation Then
            Exit For
        Else
            Row += 1
        End If
    Next

    Console.WriteLine("Column:" & Column & " Row:" & Row)

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2015-02-11
    • 1970-01-01
    • 2019-11-07
    • 2014-04-27
    相关资源
    最近更新 更多