Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,810 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,246 people online right now. Registration is fast and FREE... Join Now!




Moving form with FormBorderStyle = None?

2 Pages V  1 2 >  
Reply to this topicStart new topic

Moving form with FormBorderStyle = None?, I am using the software called Visual Studio 2008 Express Edition

Mommy
4 Aug, 2008 - 03:21 PM
Post #1

D.I.C Head
Group Icon

Joined: 4 Aug, 2008
Posts: 104



Thanked: 2 times
My Contributions
Hello, I just started learning VB.NET today, which means yesterday, cause it's actually 01:11 here (1:11 AM)..
I am using the software called Visual Studio 2008 Express Edition.

I've created this calculator on my own, and the past hour I've been messing with the design..
Right now I am wondering how I can move the form around, with the FormBorderStyle set to none (no borders (means no exit button, minimize etc.. I made those myself smile.gif)

This is how it currently looks :

IPB Image


Everything works on it..

What I'm looking for is that I should be able to press anywhere on a place that isn't used (black place) and drag it around smile.gif.

Thanks, this seems like a nice community smile.gif.


EDIT:

I forgot to mention another issue that I have smile.gif.
The textbox on the calculator accepts any signs and letters, how can I make it so it just accepts numbers? smile.gif.

This post has been edited by Mommy: 4 Aug, 2008 - 03:23 PM
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Moving Form With FormBorderStyle = None?
4 Aug, 2008 - 04:00 PM
Post #2

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 800



Thanked: 51 times
Dream Kudos: 2175
My Contributions
Here are the basics dragging a form.
vb

Class Form1
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown

If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp

If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove

If IsFormBeingDragged Then
Dim temp As Point = New Point()

temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
End Class

User is offlineProfile CardPM
+Quote Post

Mommy
RE: Moving Form With FormBorderStyle = None?
4 Aug, 2008 - 04:28 PM
Post #3

D.I.C Head
Group Icon

Joined: 4 Aug, 2008
Posts: 104



Thanked: 2 times
My Contributions
QUOTE(AdamSpeight2008 @ 4 Aug, 2008 - 05:00 PM) *

Here are the basics dragging a form.
vb

Class Form1
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown

If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp

If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove

If IsFormBeingDragged Then
Dim temp As Point = New Point()

temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
End Class



Woah, didn't think it'd be so much code! Thanks a lot for the quick answer, I would never have found out this on my own wink2.gif.

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Moving Form With FormBorderStyle = None?
4 Aug, 2008 - 04:43 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,956



Thanked: 43 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You can find a snippet here which shows how to use KeyChar in the KeyPress event of the TextBox to limit which characters are allowed.
User is online!Profile CardPM
+Quote Post

Mommy
RE: Moving Form With FormBorderStyle = None?
5 Aug, 2008 - 02:27 AM
Post #5

D.I.C Head
Group Icon

Joined: 4 Aug, 2008
Posts: 104



Thanked: 2 times
My Contributions
Hmm when I add this, it gives me the error: Error 1 'KeyChar' is not a member of 'System.EventArgs'. and Error 5 'Handled' is not a member of 'System.EventArgs'.

I don't really understand what this means, but probably just one stupid thing I'm doing wrong. I added it to the code to be executed when you click the textbox. That's right, right?
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Moving Form With FormBorderStyle = None?
5 Aug, 2008 - 03:50 PM
Post #6

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 800



Thanked: 51 times
Dream Kudos: 2175
My Contributions
QUOTE(Mommy @ 5 Aug, 2008 - 11:27 AM) *

Hmm when I add this, it gives me the error: Error 1 'KeyChar' is not a member of 'System.EventArgs'. and Error 5 'Handled' is not a member of 'System.EventArgs'.

I don't really understand what this means, but probably just one stupid thing I'm doing wrong. I added it to the code to be executed when you click the textbox. That's right, right?

No it needs to be in the textbox's KeyPress event.
User is offlineProfile CardPM
+Quote Post

Mommy
RE: Moving Form With FormBorderStyle = None?
6 Aug, 2008 - 12:13 PM
Post #7

D.I.C Head
Group Icon

Joined: 4 Aug, 2008
Posts: 104



Thanked: 2 times
My Contributions
Ah okay, I fixed it smile.gif.
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Moving Form With FormBorderStyle = None?
6 Aug, 2008 - 08:19 PM
Post #8

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 800



Thanked: 51 times
Dream Kudos: 2175
My Contributions
The dragging code can be made slightly smaller,
vb

Public Class Form1
Dim IsDraggingForm As Boolean = False
Private MousePos As New System.Drawing.Point(0, 0)

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
IsDraggingForm = True
MousePos = e.Location
End If
End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then IsDraggingForm = False
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
If IsDraggingForm Then
Dim temp As Point = New Point(Me.Location + (e.Location - MousePos))
Me.Location = temp
temp = Nothing
End If
End Sub

User is offlineProfile CardPM
+Quote Post

vzybilly
RE: Moving Form With FormBorderStyle = None?
9 Oct, 2008 - 03:43 PM
Post #9

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 10


My Contributions
umm i have been working with this code for afew hours now and have gotten nowhere, but back to my Q

How do you move the form with the keys? i have:

CODE

    Dim fade As Integer = 100
    Dim X As Integer = 1
    Dim Y As Integer = 1

    Private Sub forfunzys_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer2.Enabled = True
    End Sub

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Up Then
           'the program does not even do this when i press up so i can't test to see if the other part works...
            Me.TimerUp.Enabled = True
        ElseIf e.KeyCode = Keys.Down Then
            Me.TimerDown.Enabled = True
        ElseIf e.KeyCode = Keys.Left Then
            Me.TimerLeft.Enabled = True
        ElseIf e.KeyCode = Keys.Right Then
            Me.TimerRight.Enabled = True
        ElseIf e.KeyCode = Keys.Escape Then
            End
        End If
    End Sub
    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
        If e.KeyCode = Keys.Up Then
            Me.TimerUp.Enabled = False
        ElseIf e.KeyCode = Keys.Down Then
            Me.TimerDown.Enabled = False
        ElseIf e.KeyCode = Keys.Left Then
            Me.TimerLeft.Enabled = False
        ElseIf e.KeyCode = Keys.Right Then
            Me.TimerRight.Enabled = False
        ElseIf e.KeyCode = Keys.Escape Then
            End
        End If
    End Sub
    Private Sub updatez()
        'Dim XY As New System.Drawing.Point(X, Y)
        'Me.DesktopBounds.Right(X, 500)
        'My.Forms.forfunzys.Location(XY)
        Me.Location = New Point(X, Y)
        'Me.DesktopBounds = New Point(XY)
        'Me.DesktopLocation = New Point(X, Y)
        'Dim temp As Point = New Point(Me.Location + (e.Location - MousePos))
        'Me.Location = temp
        'temp = Nothing
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If fade = 10 Then
            Timer1.Enabled = True
            Timer2.Enabled = False
        Else
            fade = fade - 1
            Me.Opacity = fade / 100
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If fade = 100 Then
            Timer1.Enabled = False
            Timer2.Enabled = True
        Else
            fade = fade + 1
            Me.Opacity = fade / 100
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Close()
    End Sub

    Private Sub TimerRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerRight.Tick
        X = X + 25
        updatez()
    End Sub

    Private Sub TimerLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerLeft.Tick
        X = X - 25
        updatez()
    End Sub

    Private Sub TimerDown_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerDown.Tick
        Y = Y + 25
        updatez()
    End Sub

    Private Sub TimerUp_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerUp.Tick
        Y = Y - 25
        updatez()
    End Sub


i have taken bits of code from my other progs and some stuff here but i have not been able to get it to work yet...
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Moving Form With FormBorderStyle = None?
9 Oct, 2008 - 07:44 PM
Post #10

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 800



Thanked: 51 times
Dream Kudos: 2175
My Contributions
Here how to move a form with keys, (Alt + Arrow Key)
vb

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt Then
Dim MoveDist as Integer=2

Select Case e.KeyCode
Case Keys.Left
Me.Left -= MoveDist
Case Keys.Right
Me.Left += MoveDist
Case Keys.Up
Me.Top -= MoveDist
Case Keys.Down
Me.Top += MoveDist
End Select
My.Application.DoEvents()
End If
End Sub

User is offlineProfile CardPM
+Quote Post

vzybilly
RE: Moving Form With FormBorderStyle = None?
9 Oct, 2008 - 08:16 PM
Post #11

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 10


My Contributions
the line:

CODE
My.Application.DoEvents()


does not work, it says DoEvents is not a member of...
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Moving Form With FormBorderStyle = None?
9 Oct, 2008 - 08:23 PM
Post #12

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 800



Thanked: 51 times
Dream Kudos: 2175
My Contributions
QUOTE(vzybilly @ 10 Oct, 2008 - 05:16 AM) *

the line:

CODE
My.Application.DoEvents()


does not work, it says DoEvents is not a member of...

Enable Application Framework (in the applications settings) needs to be ticked.

Edit: It still works if you remove that line of code.

This post has been edited by AdamSpeight2008: 9 Oct, 2008 - 08:26 PM
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 02:32PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month