If I Add An Item Onto A Form, How Do I Go About Dragging It Around?
I been searching on these forums but cant find anything using VB 6
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Menu Item Dragging
One facility that Windows provides with certain menus is the ability to drag and drop items in them to different positions so that the user can re-order them (see for instance the Favorites menu in Internet Explorer and the Programs menu in the Start menu). So what if you want to have this sort of facility in your VB application? Can it be done?
The answer is yes, although clearly it can't be done with native VB, and it does in fact require subclassing of two separate windows. The attached project provides a demonstration of how it can be done. It emulates the design used in Windows 98, which is to have a bar appear over the menu to show where the menu item being dragged will be dropped. I have not explored emulating the design used in Windows XP, which is to have a translucent copy of the menu item being dragged appear as a drag icon, but no doubt the technique to do this would be similar, if more advanced.
The stages to allowing menu item dragging and dropping are:
1. Subclass the form that contains the menus. You will need to be comfortable with the concept of subclassing in order to understand the project. If you're not, try this thread by John.
2. In the subclassing routine for the form (WindowProc of SubClassForm), set the menus to be ownerdrawn. Code for this is courtesy of Garrett Sever at EliteVB .
3. Obtain the hwnd of the menu window. This is NOT the same as the handle to the menu, which all APIs to do with menus seem to use. Instead it is the handle to a window that contains the menu. You could get this through looking for the WM_ENTERIDLE message in the form subclassing routine, which gives it to you, although I do it by waiting until the first item in the menu is drawn, and then finding it with FindWindow.
4. Subclass the menu window. This is the key to the whole thing. All of the following steps are carried out in the menu window subclassing routine (MWProc of SubClassMenuWindow). The form subclassing routine does not give you sufficient messages to provide for menu item dragging, so you have to do this.
5. When the left mouse button goes down on the menu (MWM_MOUSEDOWN, MWM_MOUSEDOWNWIN98 messages), record where it does.
6. If the mouse moves (MWM_MOUSEMOVE message) outside the drag rectangle without coming up, begin a drag operation. Get a device context for the menu window, and draw a bar onto that device context to show where the menu being dragged will be dropped if the user releases the left mouse button.
7. When the left mouse button comes up (MWM_MOUSEUP, MWM_MOUSEUPWIN98 messages), don't call the original window procedure. Instead, re-arrange the data which your menus represent, and cause the menu window to be refreshed by use of InvalidateRect. This allows the user to see the changes that he has made before the menu is dismissed.
And that's about it. It is complicated, and it is otherwise undocumented so far as I can see, but it does work. If you have any comments or find any bugs then please PM me.
Listview Dragging Item
Hello, Jusk asking if there is a possible way to drag item in the listview??
it goes like this:
Listview populate with;
Item 1
Item 2
Item 3
When I drag Item 3 to the position of Item2, it goes like this;
Item 1
Item 3
Item 2
is this possible?? if not?? what should I do??
Stop Item Dragging/moving In ListView
Is there any way you can stop the user from moving the item position in a listview?? I need them to stay the same as i added them first by code, with them being fixed for the user and not allowing any movement of item position!
thanks!
Show Item Text When Dragging A Treeview Node
Does anybody know how when dragging a treeview node, to display the text property of the node as well as the DragIcon. I want to be able to replate the drag drop behaviour of Windows Explorer, i.e while you are dragging a folder, you can see the folder name in transparent text.
I have no problem setting the DragIcon property from an imageList I have associated with the treeview. For example in the DragOver event I am setting the DragIcon based on whether the mouse is over a valid drop point. E.g. .DragIcon = LoadResPicture("NoDrop", vbResCursor)
However it only shows the DragIcon and nothing else when dragging the node. Any help appreciated.
Dragging A Form
Hi all,
I have created a form that pops up and follows the curser around the screen when you are dragging an item from one list to another. This works with a timer on the form that repeatedly repositions the form next to the curser using the GetCursorPos function. I have a text box on this form that I want the user to be able to type in whilst dragging an item. If the moue button is not held down (and the form is just following the cursor), the text box accepts text quite happily, but when the mouse is held down as you are dragging an item, te text box does not accept text any more!?
I have tried using the GetKeyState function in the timer loop combined with a loop to go through the ascii key codes, to place letters that are pressed after the existing text in the box, but that doesnt account for the other keys on the keyboard such as the curser keys, delete, backspace, etc.
Does anybody have any suggestions on how I can make the text box accept input while the mouse button is pressed and dragging?
Any help would be great
Thanks in advance, Al.
Dragging The Form
I have a form with no border. Is there a way to drag the form and move it around the screen without having the title bar to click on? thanks
Form Dragging
Ok my form is useing a graphic image over the form but im having a problem dragging the form, I keep getting Compile err0r: Sub or Function not defined.
Code:
Private Sub Label3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Drag Me
End Sub
Help
Dragging A Form
Hi all,
I have created a form that pops up and follows the curser around the screen when you are dragging an item from one list to another. This works with a timer on the form that repeatedly repositions the form next to the curser using the GetCursorPos function. I have a text box on this form that I want the user to be able to type in whilst dragging an item. If the moue button is not held down (and the form is just following the cursor), the text box accepts text quite happily, but when the mouse is held down as you are dragging an item, te text box does not accept text any more!?
I have tried using the GetKeyState function in the timer loop combined with a loop to go through the ascii key codes, to place letters that are pressed after the existing text in the box, but that doesnt account for the other keys on the keyboard such as the curser keys, delete, backspace, etc.
Does anybody have any suggestions on how I can make the text box accept input while the mouse button is pressed and dragging?
Any help would be great
Thanks in advance, Al.
Dragging Out Of My Form
Hi, I'm using drag/drop to remove certain objects from my form. I got most of it working so far.. I can drag an item over a certain object and it removes this object from the form. But i want to be able to drag the item outside the form and have it get removed as well. Any idea's?
Form Dragging
Ok, i have 3 forms, and my form1 is my main form, and what i want is that whenever the main form is dragged and moved around then the 2 other forms will move along with it.
So far i have this, but it will only work when you click on the back of the form, which i dont want as i want it to happen when you click the caption bar thing.
VB Code:
Private Done as Boolean Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Done = True End IfEnd Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Done = False End IfEnd Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)'Snapping If Done = True Then If frmMulti.SnapPlaylist.Value = 1 Then frmPlaylist.Top = Me.Top frmPlaylist.Left = Me.Left + Me.Width End If If frmMulti.SnapExtra.Value = 1 Then frmMulti.Left = Me.Left frmMulti.Top = Me.Top + Me.Height End If End IfEnd Sub
Dragging The Form
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Code:
Private Declare Function ReleaseCapture Lib "user32" () As Long
Code:
Private Const WM_MOVE = &HF012
Code:
Private Const WM_SYSCOMMAND = &H112
Code:
Sub MoveTheForm(NameOfForm As Form)
Code:
Call ReleaseCapture
Code:
Call SendMessage(NameOfForm.hwnd, WM_SYSCOMMAND, WM_MOVE, 0)
Code:
End Sub
I'm trying to make it so the user can drag the form when he clicks anywhere on the form. However, the code is not working!! I'm using the above declerations and then calling it like this:
Private Sub Form_Click()
Call MoveTheForm(Form1)
End Sub
however, this is not doing anything!! What's wrong??
Dragging The Form
is there a message or something the program receives while the window is being dragged across the screen?
i want to be able to make another form 'stick' to the bottom of this form, but i don't know how to find out if the form is being dragged.
Dragging Controls Around A Form
I have an array of shape controls on my form. At runtime, I would like the user to be able to freely drag and drop the shapes around the form using their mouse.
I was thinking that this might be something to do with Shape1_DragDrop event, but I've not managed to get this to work.
Does anyone have any ideas?
Dragging A Frame Onto A Form
Hello people,
Maybe a trivial question, but I have some problems in doing that:
Simply I need to drag a frame on a surface occupied by a FlexGrid (fg). The only thing I need is this:
Ckick on the frame, drag it to another position of the fg and drop there.
I have set this code:
Private Sub Frame2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Frame2.DragMode = vbManual
m_intX = X
m_intY = Y
Frame2.Drag vbBeginDrag
Private Sub fg_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Frame2.Move X - m_intX, Y - m_intY
End Sub
Indeed the thing works, but only if the mouse pointer is not dragged on the frame itself. It is not so easy to explain, therefore please give me a suggestion to do that better.
Thank You to Everyone
Regards
TdP
Dragging Controls In A Form
This is what I would like to accomplish: I am dragging an image that will drop somewhere in the form. This is what's in my code:
VB Code:
Private LeftofImage1 As LongPrivate TopofImage1 As LongPrivate inmovement As Boolean Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) LeftofImage1 = X TopofImage1 = Y inmovement = TrueEnd Sub Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If inmovement = True Then Image1.Top = Image1.Top - (TopofImage1 - Y) Image1.Left = Image1.Left - (LeftofImage1 - X) End IfEnd Sub Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) inmovement = FalseEnd Sub
LeftofImage1 and TopofImage1 are the X and Y values of my image control before dragging, and inmovement checks whether or not it's still MouseDown.
Just to clairify, the image flickers to the opposite direction of where I want to go. Does anybody know how to fix this?
Form Dragging Event?
Is there any way to detect when the Form is being dragged?
I need some sort of event that fires continously when the form is being dragged, I mean like someone Mouse_Down in the titlebar and move the Form.
Some sort of Form_Resize event, but for dragging.
Prob On Dragging A Form
hello
i'm using a child form and wen i'm writing a code to drag a form on to the parent form its not working.
can anybody suggest a small example which is having a code related to form dragging
thnks
Dragging FrmSplash Form
Using VB 6.0 I added a form frmSplash in my project. I want to drag it with mose on runtime. How?
Dragging Image On Form W/ Layers
Hello all. I've created a program that allows the user to drag pictures from one form to another, and also anywhere within a form. If the user is dragging the picturebox within the same form, the picture moves with the cursor (it doesn't just appear at the new cursor position when the drag is complete). I've used the BitBlt API to accomplish some of my program.
My problem: Along with what I currently have I would like one form to have multiple layers. I would like a user to be able to click on a picture and be able to type what layer to move it to in a textbox (say 1-10), or use arrows to move it a layer up or down, or some sort of system. Annnnyway, any suggestions of how to accomplish this?
Thanx
Stop Form From Dragging Off-Screen
I've searched this quite a bit and keep coming up with the same results... all of which don't really solve the problem...
I have a form that I want users to drag, however, I do not want the form to cross the edges of the screen. That is, I do not want any part of the form to disappear outside the screen. The only code I've found close to this is one to snap the form to the edge of the screen (while still allowing it to be pushed outside the screen).
I've tried using the mouse position API for the form, but it doesn't capture the X and Y coordinates for when you're over the form's border. I understand this to only see the INSIDE of the form, and not the form's border included.
Thanks in advance!
Dragging A Command Button Around The Form
Hi everyone, i am extremely new to VB and dont know very much at all, and i need a bit of help
I want to make an extremely simple program which has one command button on a form, i want to be able to drag the command button around the form and drop it into a new position.
This is what I have so far (bearing in mind that im not sure if this is correct)
Code:
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
command1.drag vbbegindrag
end sub
And i want to know what i have to do to make the button change its position on the form depending on where you drop it, i think it is something to do with 'Command1_DragDrop' but am not sure
please try to keep it simple, im a newby
Move A Form In Win NT By Dragging The File
I am using the following code in mousemove event of a form
ReleaseCapture
Call SendMessage(me.hwnd, &H112, &HF012, 0)
This works fine and the form moves in win98 but the form doesent move at all in win NT 4. I havent tried it with other os.
Any one knows why and whats the workaround?
Thanks in advance.
-Sanjay
Sanjaykattimani@hotmail.com
-Sanjay kattimani
MScomm Troubles Dragging Non Modal Form
I experienced this problem:
If I use a MScomm control receiving a continous stream of data from a serial port and I open and drag a non modal window the operating system crash after few seconds of operation.
Anybody experienced the same?
Have someone any hints or ideas to workaround the problem?
To duplicate the effect:
1. create a new project.
2. Add a form as Form2
3. on Form1 * * * three buttons "startcom", "stopcom", "newform"
4. add a MScomm1.ocx control
5. add a label1 and edit its caption = "0"
5. Paste the below code
note: The Startcom button open the comm port 1 at 38400 (but also different baud rate generates the same problem).
The Stopcom button stop the communications
6. Run the program
7. If you click on startcom the label1 begins to count the commevent
if you click on stopcom the label1 stops to count
8. If you click on newform a new form (form2) not modal will be opened
9. If the comm port is closed you can drag the form and continue
to drag it for an indefinite period of time around the desktop
10. if you open the comm and open a newform and drag it
for a while; the software will continue to process the oncomm events
but soon all the system will crash...
Any ideas???
Thank you!
Code:::
Private Sub startcom_Click()
MSComm1.Settings = "38400,n,8,1"
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub
Private Sub stopcom_Click()
MSComm1.PortOpen = False
End Sub
Private Sub newform_Click()
Form2.Show 0
End Sub
Private Sub MSComm1_OnComm()
a$ = MSComm1.Input
Label1.Caption = Val(Label1.Caption) + 1
End Sub
MDI Child Form Auto Scroll When Dragging
Here is my problem :
I have a couple of pictureboxes in an MDI child form that is bigger than its parent MDI form.
All pictures can be dragged from one box to another.
But because not all the pictureboxes are visible ( unless you scroll the MDI form ), it is impossible to drag let say Picture1 into Picture10 because Picture10 is not accessible.
Is there a way on drag event to make the MDI Form scroll automatically when it hits the borders of the form ?
Thanx !
Finding Out If The Form Itself Is Being Moved By Dragging On The Title Bar... ?
Hello ppl...
I'm using windows 2000's layering abilities to make my form semi-transparent when a user drags it around and make it opaque when the mouse button is released. The problem is that I can't find a way to check if the form is being dragged around. The mouse events of the form do not fire when the title bar is being dragged. All i want is a mechanism that tells me if the title bar is being dragged or not. Can anyone help me?
Asim
Dragging Form / Slider Etc. Stops Execution
My code needs to transmit regular packets onto a serial bus, however when the user holds the mouse down on a slider etc. then the transmit function stops until they let go
Is there a clever way to continue processing whilst this is happening?
I am thinking multithreading might be a way around this problem but is there a simpler way?
Cheers
Normal Form And Dialog / Modal Form Sharing A Taskbar Item
My situation is I have a normal form (aka not a modal form), and a modal form that serves as an about window. When you show the modal form, all the items in the task bar lose focus. If you switch windows, and then go back to the 1 taskbar item for my program, again the taskbar item for my application loses focus and no taskbar item has focus.
I'm trying to make my application do the same thing as Word (for example). If you show the About window, the About window always has focus until you close it, but both the application window and the about form "share" the taskbar item, so when you click on Word in the taskbar, it doesn't lose focus.
Is this possible in Visual Basic 6?
Thanks in advance,
L. Whiteside
Item From One Form To Another
I have 2 MDIChilds:
1st: 5 labels
2nd: listbox with some items and a button
Now i want when you click on the label, Form2 will open (i already have that) but then when you select an item from Form2 and you click on the button it needs to copy the caption of that item.
EX: i click on label 1(4) at Form1, Form2 will open and i select the item 'red'. Then i click on the button and the caption of label1(4) has to become 'red'.
How To Search Listbox For Item If Item Not Found Add Item?
Hi, lol man I cant find nothing today when I search the forum.
This my latest problem, How do I search a listbox for an item lets say "Game Over" And if the item is found the program does nothing, but if the item is not found it will add "Game Over"
Thanks Again
Highlight Item With Focus On Form
Dopey question that is totally annoying me.
Form contains many text boxes for input, and the tab order tabs through them. As the tab moves to the next box, it highlights that box (as if selected)..
But the FIRST box needs to be selected when I enter the form.. right now the insertion bar is there..
None of the properties seem to fix this for me..
"set focus" doesn't do it.
thanks
-kak5157
Assigning New Form To A Menu Item
I want to assign a new form to a menu item. The idea is that one should be able to put in six numbers in a popup windoe, which should show when choosing the menu item. Any suggestions on how to do this?
A Form With Borderstyle 0 And A Menu Item, Not Possible?
I want a window with no borders or title bar, so I set the borderstyle to 0. So far so good. But I also want to have a popupmenu, so I create a menu with menueditor and set visible to false. But as soon as I have a menu item with my form, the titlebar of the window is back. Am I doing something wrong?
Help Removing An Array Item From Form
Hi,
I'm not able to figure out how to remove an array element from a form and immediately "repaint" the form without that element. I have included the code. Any help would be appreciated. Thanks, Tom
Imports System.io
Public Class Form1
Inherits System.Windows.Forms.Form
Public Class LabelI
Inherits System.Windows.Forms.Label
End Class
Public Class ButtonI
Inherits System.Windows.Forms.Button
End Class
Public a, b, c, d, e, f, g, h, i, lloc, cloc As Integer
Public salesdir, orderfile(500), bbdir, evar, oldfilename As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
salesdir = "c:/ROUNDING THIRD/Pending Sale/"
startit()
End Sub
Sub startit()
readdirectory() 'get all the file names in the directory
paintpage() ' create the screen
End Sub
Sub readdirectory()
a = 0
oldfilename = Dir$((salesdir) & "*.*")
While oldfilename <> ""
oldfilename = Dir$()
If (oldfilename) <> "" Then
If (oldfilename) <> "0000000000.TXT" Then
a = ((a) + 1)
orderfile(a) = (oldfilename)
End If
End If
End While
End Sub
Sub paintpage()
Dim ckb(500) As ButtonI
Dim albl(500) As LabelI
lloc = 130
b = 1
Me.Refresh()
While ((b) < ((a) + 1))
If System.IO.File.Exists((salesdir) & (orderfile(b))) Then
albl(b) = New LabelI
ckb(b) = New ButtonI
With albl(b) ' creates a label containing the name of a file
.Refresh()
.Size = New Size(1100, 16)
.Location = New Point(75, (lloc))
.BackColor = System.Drawing.Color.White
.TextAlign = ContentAlignment.BottomLeft
.Show()
.Font = New System.Drawing.Font("Courier new", 10, FontStyle.Regular)
.Text = (orderfile(b))
.Tag = CStr(b)
End With
Controls.Add(albl(b))
AddHandler albl(b).Click, AddressOf LabelClick
With ckb(b) ' creates a button for each file name
.Refresh()
.BackColor = System.Drawing.Color.White
.ForeColor = System.Drawing.Color.White
.TextAlign = ContentAlignment.BottomLeft
.Size = New Size(40, 16)
.Location = New Point(35, (lloc))
.Show()
.Tag = CStr(b)
.Text = albl(b).Text
End With
Controls.Add(ckb(b))
AddHandler ckb(b).Click, AddressOf buttonclick
lloc = ((lloc) + 20) 'incrument the row
End If
b = ((b) + 1)
End While
End Sub
Private Sub buttonclick(ByVal sender As Object, ByVal e As EventArgs)
evar = (CType(sender, ButtonI).Text) ' if button clicked, passes the name of the file to be deleted
Try
System.IO.File.Delete((salesdir) & (evar))
Catch
Msgbox("Error trying to delete "&(evar))
End Try
End Sub
Private Sub LabelClick(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End 'exit program
End Sub
End Class
How To Programatically Click An Item On Another Form
On one of my forms in my current project I am using a Sheridan ActiveListBar (an Outlook style toolbar down the left side of the form). I want to be able to programaticaaly select a listbar item from another form. Is this possible.
Listed below is the sketal code for the Activelistbar on frmMain.
VB Code:
Private Sub ssMainListbar_ListItemClick(ByVal ItemClicked As Listbar.SSListItem) Select Case ItemClicked.Key Case "Main" Case "Main View" 'Do Something Here 'Do Something Here 'Do Something Here Case "Wordprocessing" 'Do Something Here 'Do Something Here 'Do Something Here Case "DB Tools" Case "Adhoc Query Design Tool" 'Do Something Here 'Do Something Here 'Do Something Here Case "LookupMaint" 'Do Something Here 'Do Something Here 'Do Something Here Case "Data Export" 'Do Something Here 'Do Something Here 'Do Something Here Case "Reports" Case "Attendance" 'Do Something Here 'Do Something Here 'Do Something Here Case "Giving History" 'Do Something Here 'Do Something Here 'Do Something Here End SelectEnd Sub
Rev. Michael L. Burns
Item Form Combo To Text1
when someone selects a item from the combo box i want it to be put into text1..i thought this was gonna be easier but i couldn't figure it out.
Call Menu Item On MDI Form
How do I call a menu item form another form.
The menu is on a MDI form and the code is inside of a sub on on of the childforms.
I have this, but get the error:
Invalid use of property
Code:Call MDIMain.mnuEditCourse
--------------------------------------------------------------------------------
aikidokid
We all have to start somewhere .... I think I'm at somewhere
Refer To An Item In A Listbox For Another Form
I have one more question. I am working on a form that needs to keep in memory the first and last name of a student that is in a list box and once you move to another form whatever student you are clicked on will show up on the second form in a label box. Does anyone have any suggestions on how to populate this data into the other form?
Thanks,
Ryan Gagliano
Load Item Form A File To Combobox
i need help with combobox. the problem is i dont know how to load a list from a life to a combobox. i want to load a list that have country names. i need something like this below:
Private Sub Form_Load()
LoadItem Combo1 App.exe, "Filename.txt"
End Sub
but i dont know how to code the loaditem fuction so that it load at startup and combo1 should show:
place 1
place 2
place 3... etc.
please help me.
Pre Select ListView Item On Form Load...
Is it possible to pre-select a list view item when my form loads. The list contains 5 items and I would like the first one to be selected (highlighted in blue).
Thanks...
Passing ListView Item To TextBoxes On Another Form
Hello,
What you suggest (as far as I understand with my limited knowledge of VB) works fine if I know which record has been selected to update (i.e. your example listview.listitems(2).subitems(i) tells me I want the second record of the list. Is there a way to substitute the "2" with variable (or some other means to soft code). Also, once I get the data I need. how do I pass and accept this into another form?
Thanks!
|