| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 499 人关注过本帖
标题:如何实现按钮拖放到TableLayoutPanel
只看楼主 收藏
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
结帖率:85.29%
  问题点数:0  回复次数:9   
如何实现按钮拖放到TableLayoutPanel
请教:如何实现按钮或其他控件拖放到TableLayoutPanel中的任何格中?谢谢
附件: 您没有浏览附件的权限,请 登录注册
2017-08-03 10:27
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
  得分:0 
期待大家指点!!
2017-08-03 15:44
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
  得分:0 
请大家指点指点!!
2017-08-04 16:11
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
  得分:0 
兄弟姐妹们,我提的问题是不是不能实现啊?期待大家给一个答案!谢谢
2017-08-08 11:22
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
  得分:0 
有谁能指点指点吗?谢谢
2017-08-29 11:18
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
  得分:0 
真的无法实现我的要求吗?好期待大家给个答案,谢谢
2017-09-11 16:08
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1480
专家分:4989
注 册:2007-10-7
  得分:0 
楼主的版本高,我的.net版本暂时打不开你的项目
能详细描述下么?在窗口中拖动一个按钮不是问题吧?下面的是在窗体上拖动一个按钮到任意位置的例子:

程序代码:

    Private nLocation As Point

    Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
        nLocation = e.Location
    End Sub

    Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
        Dim pos_x, pos_y As Int32
        If e.Button = MouseButtons.Left Then
            pos_x = Button1.Location.X + (e.X - nLocation.X)
            pos_y = Button1.Location.Y + (e.Y - nLocation.Y)
            Button1.Location = New Point(pos_x, pos_y)
        End If
    End Sub


===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2017-09-17 18:22
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
  得分:0 
回复 7楼 不说也罢
版主,我想实现的就是能将一个控件拖动,并自动铺满
附件: 您没有浏览附件的权限,请 登录注册
2017-09-18 14:08
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1480
专家分:4989
注 册:2007-10-7
  得分:0 
这里粗略地写了一个例子,实在没有时间,你琢磨一下吧。基本上可以实现你要的功能。只是计算上有些误差。
程序代码:

'环境:VS2008
'
你测试时,需要在窗体上画一个button,其他什么也不用做。
'
当然,你制作时,可以参考下面的例子,考虑动态加载你的button

Public Class Form3
    Private nLocation As Point
    Private TableLayoutPanel() As TableLayoutPanel
    Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
        nLocation = e.Location
        With Button1
            If .Parent Is Me Then Exit Sub
            .Location = .Parent.Location
            .Width = .Parent.Width - 10
            .Height = .Parent.Height - 10
            .Parent = Me
            .Dock = DockStyle.None
            .BringToFront()
        End With
    End Sub

    Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
        Dim pos_x, pos_y As Int32
        If e.Button = MouseButtons.Left Then
            pos_x = Button1.Location.X + (e.X - nLocation.X)
            pos_y = Button1.Location.Y + (e.Y - nLocation.Y)
            Button1.Location = New Point(pos_x, pos_y)
        End If
    End Sub

    Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
        For i As Integer = TableLayoutPanel.Count - 1 To 0 Step -1
            If Button1.Left > TableLayoutPanel(i).Left And Button1.Top > TableLayoutPanel(i).Top Then
                Button1.Parent = TableLayoutPanel(i)
                Button1.Dock = DockStyle.Fill
                Exit For
            End If
        Next
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        Dim i, num As Integer
        Dim nTop As Long = 0, nLeft As Long = 0
        num = 100

        ReDim TableLayoutPanel(0 To num - 1) '根据输入的指定数值定义TableLayoutPanel对象

        nTop = 200 '从这里开始画TableLayoutPanel
        For i = 0 To num - 1
            Application.DoEvents() '设置程序友好响应
            TableLayoutPanel(i) = New TableLayoutPanel
            Controls.Add(TableLayoutPanel(i))
            With TableLayoutPanel(i)
                .SetBounds(nLeft, nTop, 50, 50) '将标签的高度设为50,宽度设为50
                .BorderStyle = BorderStyle.FixedSingle
                .Tag = i '这个属性用来识别每个TableLayoutPanel对象
                .Visible = True
                '为即将创建的下一个TableLayoutPanel设置坐标
                nLeft += .Width - 1   '将标签的左右间距设为10
                If nLeft + .Width >= Me.Width Then '如果下一个TableLayoutPanel将超出窗体的宽度,换行显示
                    nLeft = 0
                    nTop += .Height - 1 '标签的行间距
                End If
            End With
        Next i
    End Sub

End Class

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2017-09-23 20:27
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:330
专家分:134
注 册:2009-3-16
  得分:0 
回复 9楼 不说也罢
谢谢版主,正是我想要的效果!!再次感谢
2017-09-27 08:54







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.088437 second(s), 8 queries.
Copyright©2004-2017, BCCN.NET, All Rights Reserved