473,799 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_MouseMov e 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_MouseDow n(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseDow n
Move.MouseDown = True
Move.MouseOffse t = New Point(e.X, e.Y)
End Sub

Private Sub Label1_MouseMov e(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseMov e
If e.Button = Windows.Forms.M ouseButtons.Lef t Then
If Not Move.MouseDown Then Exit Sub

''New way
'Dim Dif As Point = New Point(e.X, e.Y)
'Dif.Offset(Mov e.MouseOffset)
'Panel1.Locatio n = Dif
'Move.MouseOffs et = Dif
'Exit Sub
'Old way
Dim DifX As Integer = Move.MouseOffse t.X - e.X
Dim DifY As Integer = Move.MouseOffse t.Y - e.Y

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

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles Me.Load
With Label1
.AutoSize = False
.BorderStyle = BorderStyle.Fix edSingle
.BackColor = System.Drawing. SystemColors.Ac tiveCaption
.ForeColor = System.Drawing. SystemColors.Ac tiveCaptionText
.Dock = DockStyle.Top
End With
Panel1.BorderSt yle = BorderStyle.Fix edSingle
End Sub
End Class
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '''''''''

Jul 18 '06 #1
2 1237
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_MouseMov e 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_MouseDow n(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseDow n
Move.MouseDown = True
Move.MouseOffse t = New Point(e.X, e.Y)
End Sub

Private Sub Label1_MouseMov e(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseMov e
If e.Button = Windows.Forms.M ouseButtons.Lef t Then
If Not Move.MouseDown Then Exit Sub

''New way
'Dim Dif As Point = New Point(e.X, e.Y)
'Dif.Offset(Mov e.MouseOffset)
'Panel1.Locatio n = Dif
'Move.MouseOffs et = Dif
'Exit Sub
'Old way
Dim DifX As Integer = Move.MouseOffse t.X - e.X
Dim DifY As Integer = Move.MouseOffse t.Y - e.Y

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

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles Me.Load
With Label1
.AutoSize = False
.BorderStyle = BorderStyle.Fix edSingle
.BackColor = System.Drawing. SystemColors.Ac tiveCaption
.ForeColor = System.Drawing. SystemColors.Ac tiveCaptionText
.Dock = DockStyle.Top
End With
Panel1.BorderSt yle = BorderStyle.Fix edSingle
End Sub
End Class
'''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''

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

Private StartPoint as Point
Private Sub Label1_MouseDow n(ByVal sender As Object, ByVal e _
As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseDow n
StartPoint = New Point(e.X, e.Y)

End Sub

Private Sub Label1_MouseMov e(ByVal sender As Object, ByVal e _
As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseMov e
If e.Button = Windows.Forms.M ouseButtons.Lef t Then
Dim mousePos As Point = New Point(e.X, e.Y)
Panel1.Location = New Point(Panel1.Le ft + (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
1903
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 which is located on another computer. The problem is they don't show up in the toolbox. What's wrong ? -- Adam
4
5855
by: Rudolf Ball | last post by:
Hi NG, how can I programmatically add items to the toolbox? Any links? Thank you Rudi
4
3142
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 controls. 2). I start a new solution and create an Application 3). I add the existing project with my controls to the solution, then create the reference.
2
6807
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 is contained in the same assembly as the control. As far as I know, the only way to do this using the designer is to add the UserControl-derived object
10
1539
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 references my first library in order to protect the exposed components. To make things easier I'll refer to my licensing library as licensinglibrary.dll and my control library as controllibrary.dll. When I try to add mycontrollibrary to the toolbox...
1
1411
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 the usual icons back. It feels a bit like the old ShellIconCache problem Windows used to suffer from?? Siv
7
4616
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; which include: DataSet, DataGridView, BindingSource, etc. This means that Label, Textbox, button, etc are all unavailable. My "General" option in Toolbox states "There are no useable controls in this group." I can run apps ok, & if I copy a...
5
3753
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 project. The original code for that control was written in VS 2003 for .NET 1.1. I created a Web Project and pulled the VB module into the project. I compared the syntax to the VB template classs that was built and it looked very similar. I then...
11
1557
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 job perspective. I am a VB.NET developer, and have been developing in VB.NET (also ASP.NET) for approx. 3.5 years. Prior to that, I developed in VB6/VB5/VB4 and classic ASP for approx. 10 years.
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10243
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.