Hi .paul., im having a problem, could you help, im using the visual studio 2008 version, i can import the class etc into a new blank project and it all works great, how ever everytime i try to import it into my current project i get this error:
Steps i take to import it:
1, Import the .jpg resource
2, Reference the MoveResizeControl
3, Add controlHandler.vb tot he solution
4, add in the code from form1.
Hey, ok seems in a pre made project all the references were not been auto imported, so ive done them and it now builds with no error, but it messes the BG up, take a look (BG is normally black)
Hey, no im only using BG color, no image, on the form i have a combo box which changes bg color themes and out of the 6 other color themes, but there not triggered, so they shouldn't be affecting this, right? (O_o).
When it loads with the red X its partially functional, the 2 picture boxes can be clicked dona nd moved/resized, the movement when moving them tho feels very sluggish and choppy compared tot he demo project or when there added to a new project.
That part, on page load the form is set to just be on default settings which is the BG color of the page set to black, i had thought this code would conflict, but as none of the themes are selected just the default one i thought it'd be ok.
Theres also a similar combobox used to change between some preset layouts, heres that code:
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If (ComboBox1.SelectedItem = "Standard") Then
''folders
ListBox1.Location = New Point(8, 72)
ListBox1.Size = New Size(419, 394)
''files
ListBox2.Location = New Point(8, 484)
ListBox2.Size = New Size(419, 225)
''serial:
serial.Location = New Point(451, 501)
''name:
namefull.Location = New Point(451, 469)
namefull.Size = New Size(534, 26)
''region:
flagu.Location = New Point(451, 533)
flagj.Location = New Point(451, 533)
flage.Location = New Point(451, 533)
''version:
version.Location = New Point(940, 501)
''genre:
genre.Location = New Point(637, 501)
''Date:
date1.Location = New Point(808, 501)
''front:
pboxGameCover.Size = New Size(261, 370)
pboxGameCover.Location = New Point(455, 82)
''back:
pboxGameCoverA.Show()
pboxGameCoverA.Size = New Size(261, 370)
pboxGameCoverA.Location = New Point(722, 82)
ElseIf (ComboBox1.SelectedItem = "Large Front") Then
''folders
ListBox1.Location = New Point(8, 72)
ListBox1.Size = New Size(419, 290)
''files
ListBox2.Location = New Point(8, 368)
ListBox2.Size = New Size(419, 147)
''serial:
serial.Location = New Point(8, 553)
''name:
namefull.Location = New Point(8, 521)
namefull.Size = New Size(419, 26)
''region:
flagu.Location = New Point(315, 585)
flagj.Location = New Point(315, 585)
flage.Location = New Point(315, 585)
''version:
version.Location = New Point(365, 553)
''genre:
genre.Location = New Point(194, 553)
''Date:
date1.Location = New Point(8, 585)
''front:
pboxGameCover.Size = New Size(452, 627)
pboxGameCover.Location = New Point(482, 82)
''back:
pboxGameCoverA.Hide()
ElseIf (ComboBox1.SelectedItem = "Minimal") Then
''folders
ListBox1.Location = New Point(8, 72)
ListBox1.Size = New Size(284, 394)
''files
ListBox2.Location = New Point(8, 484)
ListBox2.Size = New Size(284, 134)
''serial:
serial.Location = New Point(451, 114)
''name:
namefull.Location = New Point(451, 82)
namefull.Size = New Size(534, 26)
''region:
flagu.Location = New Point(350, 82)
flagj.Location = New Point(350, 82)
flage.Location = New Point(350, 82)
''version:
version.Location = New Point(940, 114)
''genre:
genre.Location = New Point(637, 114)
''Date:
date1.Location = New Point(808, 114)
''front:
pboxGameCover.Size = New Size(261, 370)
pboxGameCover.Location = New Point(300, 157)
''back:
pboxGameCoverA.Hide()
End If
There the only bits of code which affect the forms look or layout in my project.
OK i removed the all code to do with themes, tested, same issue, so then i removed all code to do with layouts, tested again same issue.
One thing i have noticed tho, whilst testing and the red X is there etc, the pictureboxs as i said are very sluggish feeling when moving them and as there moved the re X int he BG flickers, how ever if i try to move a listbox it moves perfectly, nice smooth and fast and no flicker, so the issue seems to be around the picture boxes, my pic boxes have no code related to them currently tho,.
Just done a test to check other code, i removed all code from my project except the code for this, and the error is still there, so then i one by one deleted all controls on the form so the form is now blank except 1 pic box and a list box for testing, no code except whats there for this, and the error is still present.
i can't see where the problem is. try adding your components + code bit by bit to a project where move / resize is working + checking it's still working at each stage.
if you can isolate the problem that way, hopefully i can help more then...
Hey, sorry for the late reply, my current project is a little to far gone to rebuild but i have another part of the same project to build which ill try this in along with the same components i used in my current project and report back if one of them is causing the issue.
I am trying to use your move resize label in my project at run time but I got one small problem.
After I call add a label using this code:
Code:
Dim label() As MoveResizeLabel
Dim nlabel As Integer
Private Sub LabelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelToolStripMenuItem.Click
ReDim Preserve label(nlabel)
label(nlabel) = New MoveResizeLabel
Me.Controls.Add(label(nlabel))
label(nlabel).Location = New Point(100, 100)
label(nlabel).Text = "Label"
End Sub
The label doesn't function as good as the ones you have on your project already sitting on the form. I am able to move it but not resize it, I think it draws the square but it fails at drawing the dots. I am not very familiar with drawings in coding but if you know what should I change in code of the moveresizelabel.vb I would appreciate.
I am using the code you have posted here, the 2008 version. I am using your move resize label for my application.
This little bit is my code (I am putting one of those labels on my form at run time)
Code:
Dim label() As MoveResizeLabel
Dim nlabel As Integer
Private Sub LabelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelToolStripMenuItem.Click
ReDim Preserve label(nlabel)
label(nlabel) = New MoveResizeLabel
Me.Controls.Add(label(nlabel))
label(nlabel).Location = New Point(100, 100)
label(nlabel).Text = "Label"
End Sub
I think the problem might be somewhere in these subs:
Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
'MsgBox = 513
MyBase.WndProc(m)
Dim g As Graphics = Me.CreateGraphics
'on paint with customcolor borderstyle
If m.Msg = 15 And Me.BorderStyle = CustomBorderStyles.None Then
g.DrawRectangle(New Pen(bdrColor, 1), New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
End If
'on paint if selected
If m.Msg = 15 And Me.Selected = True Then
DrawDashedRectangle()
DrawSquareResizeHandles()
End If
g.Dispose()
End Sub
Private Sub DrawSquareResizeHandles()
Dim g As Graphics = Me.CreateGraphics
g.FillRectangle(Brushes.Black, rTopLeft)
g.FillRectangle(Brushes.Black, rTopRight)
g.FillRectangle(Brushes.Black, rBotRight)
g.FillRectangle(Brushes.Black, rBotLeft)
g.FillRectangle(Brushes.Black, rTopMid)
g.FillRectangle(Brushes.Black, rBotMid)
g.FillRectangle(Brushes.Black, rMidLeft)
g.FillRectangle(Brushes.Black, rMidRight)
End Sub
Private Sub DrawDashedRectangle()
Dim g As Graphics = Me.CreateGraphics
Dim points() As Point = GetPointsForSelectedLines()
Dim count As Integer
g.DrawRectangle(Pens.White, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
For count = 0 To points.Length - 1 Step 2
If count + 1 = points.Length Then
Exit Sub
End If
g.DrawLine(Pens.Black, points(count), points(count + 1))
Next
End Sub
Last edited by MrtforCode; Jun 8th, 2010 at 10:51 AM.
oh I am sorry, the bit with the move resize label was not your code. But I still want to ask you a question about the code you have done.
You actually made mostly any control (textbox, groupbox, richtextbox, listbox...) movable and sizable except the label, or could it easily move resize a label as well? Where do I need to improve to get it working on a label as well?
Last edited by MrtforCode; Jun 8th, 2010 at 10:59 AM.
there seems to be a problem using my code with the label control + i'm not 100% sure but i think the API functions don't work with the label control
I saw the strange label behavior as well, it does not seem to work. If all you need is a simple line of text (no auto-ellipsis, auto-size, stuff like that) then you can use a PictureBox instead and draw the text manually using Graphics.DrawString.
Well, I will try to adjust the code to work for me but first I will need to study it out.
One question .paul., what makes the mouse cursor turn into 'move' cursor on mouseover the 'move' tag, can you show me the sub that does that? I could not find it, I want to apply something like this to NickThissen's label
what makes the mouse cursor turn into 'move' cursor on mouseover the 'move' tag?
the move box + the resize boxes are pictureboxes. i set their cursor property when they are added, so whenever the mouse is over them the cursor automatically changes
I would like to add an "edit" mode and "normal" mode so that the resize/move handles only show when in edit mode. How would you suggest going about that?
I would like to be able to save the controls' new sizes and layout. Does vb have an easy "save all" method to save all the page's control location and sizes?
unfortunately that doesn't work for dynamically added controls. you'll need to work something out using my.settings if your controls were added at runtime...
This class is very impressive and so simple to use, just a FYI to anybody having trouble getting this to work with labels (I know I did!) just set the AutoSizeMode to None and it works fine. The API won't work with controls that have any kind of autosizing and this includes anchor.
I have a database program that allows the user to design their own data entry screens, with an IDE very simular to VS but after a while I ran into problems with labels not moving & anchor properties on any control.
If you need to use anchors (i.e Top, Left works fine, but Top, Left, Right will not) just store the control anchors in a variable when it is selected (i.e in mControl_mousedown), then set the control anchor to Top,Left and then restore the original anchor properties in move_mousemove within the If GetCapture=0 statement.