473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Moving toolbox

Hello

I made a toolbox like thing by using a panel with a label docked on top.
I can move the toolbox by dragging on the label. I've coded it, VB6 style
and got no problem. Then I tried to use new VB.NET way and now I'm stuck.
If you examine Label1_MouseMove event you'll see both methods.
Can anybody fix it?

To execute the code:
1-) Add a panel: Panel1
2-) Add a label into panel (Label1)
Then run...

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''
Public Class Form1

Private Structure MoveStructure
Public MouseOffset As Point
Public MouseDown As Boolean
End Structure
Private Move As MoveStructure

Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
Move.MouseDown = True
Move.MouseOffset = New Point(e.X, e.Y)
End Sub

Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
If Not Move.MouseDown Then Exit Sub

''New way
'Dim Dif As Point = New Point(e.X, e.Y)
'Dif.Offset(Move.MouseOffset)
'Panel1.Location = Dif
'Move.MouseOffset = Dif
'Exit Sub
'Old way
Dim DifX As Integer = Move.MouseOffset.X - e.X
Dim DifY As Integer = Move.MouseOffset.Y - e.Y

With Panel1
.Top = .Top - DifY
.Left = .Left - DifX
End With
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With Label1
.AutoSize = False
.BorderStyle = BorderStyle.FixedSingle
.BackColor = System.Drawing.SystemColors.ActiveCaption
.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
.Dock = DockStyle.Top
End With
Panel1.BorderStyle = BorderStyle.FixedSingle
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''

Jul 18 '06 #1
2 1216
On Tue, 18 Jul 2006 19:14:15 +0300, "nime" <ea****@planev.comwrote:
>Hello

I made a toolbox like thing by using a panel with a label docked on top.
I can move the toolbox by dragging on the label. I've coded it, VB6 style
and got no problem. Then I tried to use new VB.NET way and now I'm stuck.
If you examine Label1_MouseMove event you'll see both methods.
Can anybody fix it?

To execute the code:
1-) Add a panel: Panel1
2-) Add a label into panel (Label1)
Then run...

''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''
Public Class Form1

Private Structure MoveStructure
Public MouseOffset As Point
Public MouseDown As Boolean
End Structure
Private Move As MoveStructure

Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
Move.MouseDown = True
Move.MouseOffset = New Point(e.X, e.Y)
End Sub

Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
If Not Move.MouseDown Then Exit Sub

''New way
'Dim Dif As Point = New Point(e.X, e.Y)
'Dif.Offset(Move.MouseOffset)
'Panel1.Location = Dif
'Move.MouseOffset = Dif
'Exit Sub
'Old way
Dim DifX As Integer = Move.MouseOffset.X - e.X
Dim DifY As Integer = Move.MouseOffset.Y - e.Y

With Panel1
.Top = .Top - DifY
.Left = .Left - DifX
End With
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With Label1
.AutoSize = False
.BorderStyle = BorderStyle.FixedSingle
.BackColor = System.Drawing.SystemColors.ActiveCaption
.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
.Dock = DockStyle.Top
End With
Panel1.BorderStyle = BorderStyle.FixedSingle
End Sub
End Class
''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''

To simply move a panel via a top-docked label:

Private StartPoint as Point
Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
StartPoint = New Point(e.X, e.Y)

End Sub

Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim mousePos As Point = New Point(e.X, e.Y)
Panel1.Location = New Point(Panel1.Left + (mousePos.X - StartPoint.X), _
Panel1.Top + (mousePos.Y - StartPoint.Y))

End If

End Sub
You may want to expand the example to restrict Panel1 to the forms ClientRectangle.

Gene

Jul 18 '06 #2
That's what I did succesfully : )
I just tried to use .Offset method instead of calculating a few things...


Jul 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adam Nowotny | last post by:
I've created library with some "user controls" and they all showed up in the toolbox, so it is easy to drag them to a form in Forms Designer. Now we want to use the controls in our main project...
4
by: Rudolf Ball | last post by:
Hi NG, how can I programmatically add items to the toolbox? Any links? Thank you Rudi
4
by: Justin | last post by:
I am having trouble adding some of my existing controls to my toolbox in VS.NET. Here's what is going on: 1). I have an existing project that is a Windows Control Library with a bunch of...
2
by: Chien Lau | last post by:
I frequently define internal UserControl-derived classes in my WinForms apps: internal class MyUserControl:UserControl{ ... } I'll often need to embed these controls in a Form, whose class...
10
by: Nak | last post by:
Hi there, I'm having problems with the Toolbox in VB.NET 2002 Standard. I have 2 class libraries, 1 contains licensing classes and references nothing but standard namespaces and the other...
1
by: Siv | last post by:
Hi, All of a sudden half of my VS.NET 2005 toolbox icons have got what looks like a chart icon instead of their usual one. What gives and why does it happen?? More importantly, how do I get...
7
by: gtrDayve | last post by:
Recently I ran all my Windows Updates which included many for Visual Studio 2005, & now when I open VS05 (using ASP.NET, VB.NET), all my toolbox options are grayed out except for the Data options;...
5
by: John Kotuby | last post by:
Hi all, This is my first time trying to creaet and use a custome Web Control in a Web Site project in ASP.NET 2.0 with VS 2005 and VB. I created the control in a separate Web Control Library...
11
by: Mark Braswell | last post by:
Hello, I would like to hear people's thoughts and opinions on the best way for a VB.NET developer to move into C#. This is specifically from a job perspective, and specifically from a UK based...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.