Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI Coding
12-31-2009, 08:20 AM (This post was last modified: 12-31-2009 08:23 AM by FreckleS.)
Post: #1
GUI Coding
Got bored today so I did a bit of thinking and came up with this, it is like the code I have posted before on moving the form with no border style etc. Instead of having crappy buttons though for Close and minimize and all that crap you can custom create them in photoshop or whatever that you design your form in then just code their functions in. I still however have crappy pictures cause I was just testing not actually making something, anyway.

What to do. I make the form in Photoshop or whatever image editor you have. I then use the Ruler tool to rule up and across my buttons.
[Image: formRules.png]

Then I read the coordinates of the corner points and jot them down.
[Image: formCorners.png]

So.
Close Button:
X must be within 384px and 392px
Y must be within 12px and 20px

Minimize Button:
X must be within 372px and 380px
Y must be within 12px and 20px - They are parallel with Close Button.

Form Border:
The border goes the entire width of the form so I won't need an X value but. Also because it covers all the way to the top of the form I will only need 1 Y value, it will be the larger one.
Y must be less than 39

Then in the coding I only have to do a little bit amount of logic and I can use these "buttons". You could also make rollovers and all that sort of crap with this same stuff.

Code:

Code:
Public Class frmMain
    ' Used for GUI
    Dim newPoint As New System.Drawing.Point()
    Dim x, y As Integer

    Private Sub frmMain_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        x = MousePosition.X - Me.Location.X
        y = MousePosition.Y - Me.Location.Y

        ' Clicked close or minimize
        If x > 384 And x < 392 And y > 12 And y < 20 Then ' Close
            Application.Exit()
        ElseIf x > 372 And x < 380 And y > 12 And y < 20 Then ' Minimize
            WindowState = FormWindowState.Minimized
        End If
    End Sub

    Private Sub frmMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If e.Button = MouseButtons.Left Then
            If e.Y < 39 Then ' Within border box thing.
                newPoint = MousePosition
                newPoint.X = newPoint.X - (x)
                newPoint.Y = newPoint.Y - (y)
                Me.Location = newPoint
            End If
        End If
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FormBorderStyle = Windows.Forms.FormBorderStyle.None
    End Sub
End Class

Essentially you could code an entire GUI like this but you have to draw the line and helpful and un-needed. In Visual Basic this code is still good for creating applications where you don't want Windows forms border but you still want the form, it gives your applications more distinction and makes them look a lot more professional.

You can see my form in attachments.


Attached File(s)
.rar  Form.rar (Size: 10.01 KB / Downloads: 4)

[Image: pgsig copy.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
12-31-2009, 09:03 AM
Post: #2
RE: GUI Coding
Very good illustration. It is interesting how you are checking if mouse is in that area. But i would rather add pictures for closing and minimizing over the background picture and just add procedure of closing and minimizing inside of click procedure of those pictures.
And another thing is maximizing, in this case program size can not be changed but that is not a problem at all, because loads of programs doesn't have that option.

"I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein
Visit this user's website Find all posts by this user
Quote this message in a reply
12-31-2009, 09:33 AM
Post: #3
RE: GUI Coding
Yeah that is how I usually do it. I am getting quite sick of it cause I hate creating the new pictures then testing if it will fit in my design so with the minimize and close that will most likely never need to be moved I can just code them into the design. Probably not good practice but it does save me time and its not too difficult.

[Image: pgsig copy.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
12-31-2009, 07:52 PM
Post: #4
RE: GUI Coding
Yeah you are right. I did some programs in Delphi so they have a good design (i am not much of a designer) and i used small pictures as buttons. But i decided to make more pictures like for on mouse enter on picture (button) so that picture changes. Than on mouse click (down) it changes and finally on mouse click (up move) it does procedure behind.
That was boring because for every button i had to make 3 pictures and to write a piece of code and if i had a dozen of buttons on forum it would take me an hour to make just that, so i gave up.

"I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein
Visit this user's website Find all posts by this user
Quote this message in a reply
01-01-2010, 12:29 PM
Post: #5
RE: GUI Coding
Yeah, they are called rollovers, Really useful in web design where you really only invert the colours of text-background.

[Image: pgsig copy.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: