any1 know how to make a square using VB.NET??
i seriously need help!!
any1 plz!!
Re: Visual Basic.NET
more details plz....
Re: Visual Basic.NET
drawing a square - you mean?
Re: Visual Basic.NET
If its a homework u should do it urself ![]()
I dont know much about VB.Net but it should be same for the .Net Framework. So u will need a Graphics object (u can override the OnPaint) . U can use the DrawRectangle() Method to draw ur square, Depending on which overload u use u ll need its parameter. Primary of which is Pen. U can simply get it like
Dim p As New Pen(Color.Red, 2)
DrawRectangle() has 3 overloads, lets simply use the one which takes integer values. Note that in .Net Rectangle structure is defined as x,y which is the start point for a rectangle, the upper left corner of the screen. width and height, u can use the hard coded integers or the variables i.e.
Dim x As Integer = 20
Dim y As Integer = 50
Dim width As Integer = 200
Dim height As Integer = 200
(bcos its square width & height r of same value)
Assuming u have aquired the grapics object gfx from PaintEventArgs of OnPaint
gfx.DrawRectangle(p, x, y, width, height)
I hope i didnt mix it up with C# :o
![]()
Re: Visual Basic.NET
http://www.google.com.pk/search?hl=en&q=system.drawing+VB.NET&btnG=Google+Search&meta=
Re: Visual Basic.NET
1st- thankz for all ur replies
HOPEFULL &Ihtesham- I have googled it but most doesn't work for VB.net 2003...i tried but there is always a problem!!! dunt know why..thats why i chose to ask u guys...
bitter- yup square
armughal- i need a to make a square and then move it up and down first than right and left.
JonyBr- thankz a lot! i m trying it now...will ask you again if i have more problem.
Re: Visual Basic.NET
Why not?
Where does it fail? Let's debug.
Re: Visual Basic.NET
nah… i think i get it.. but the problem now is to move it…up and down..
Re: Visual Basic.NET
Guys, thank a lot for all your replies but i really need your help this time. how to shad a part inside a panel? plz...i have been trying and trying but can't!! anyone here can help me please?
Re: Visual Basic.NET
GUys i seriously have problems! with vb.net!! i need ask quickly plz!!! i have this
If CurrentX > 13 Or CurrentX < 0 Then
MessageBox.Show("You lost a credit!")
Restart = True
CurrentX = 7
CurrentY = 7
End If
i want this :
MessageBox.Show("You lost a credit!") appear once only! it appear a lot of time!!
Re: Visual Basic.NET
Salam.
i seriously need ur help with vb.net
i have to make a game in with there will be a square moving and if it hits the edge a credit is lost ( there is 10 credit in total) and there is a time limit. we need a 3 levels. (easy, medium and hard) and we need to have choice of how many square to play with (1-4). we need to make the square to move up, down, left and right.
beside the codes i have a panel, 2 timers and 2 label.here is my code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim AL As New ArrayList
Public Const scope As Integer = 20
Const Xcenter As Integer = 7
Const Ycenter As Integer = 7
Dim block2 = New Class2(Xcenter, Ycenter, scope)
Dim mycredits As Integer = 10
Dim initialinterval As Integer
Dim inttimer As Integer = 30
Dim totaltime As Integer = 0
Dim diffact As Integer
Public Sub init_game()
Panel1.Width = 300
Panel1.Height = 300
mnueas.Checked = True
initialinterval = 1000
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents mnustarts As System.Windows.Forms.MenuItem
Friend WithEvents mnudif As System.Windows.Forms.MenuItem
Friend WithEvents mnumedi As System.Windows.Forms.MenuItem
Friend WithEvents mnueas As System.Windows.Forms.MenuItem
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents lbltim As System.Windows.Forms.Label
Friend WithEvents lblc As System.Windows.Forms.Label
Friend WithEvents lblcredi As System.Windows.Forms.Label
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.mnustarts = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.mnueas = New System.Windows.Forms.MenuItem
Me.mnumedi = New System.Windows.Forms.MenuItem
Me.mnudif = New System.Windows.Forms.MenuItem
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.lblc = New System.Windows.Forms.Label
Me.lblcredi = New System.Windows.Forms.Label
Me.Panel1 = New System.Windows.Forms.Panel
Me.lbltim = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Timer1
'
Me.Timer1.Interval = 1000
'
'Timer2
'
Me.Timer2.Interval = 1000
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnustarts, Me.MenuItem3, Me.MenuItem1})
'
'mnustarts
'
Me.mnustarts.Index = 0
Me.mnustarts.Text = "Start"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnueas, Me.mnumedi, Me.mnudif})
Me.MenuItem3.Text = "Difficulty"
'
'mnueas
'
Me.mnueas.Index = 0
Me.mnueas.Text = "Easy"
'
'mnumedi
'
Me.mnumedi.Index = 1
Me.mnumedi.Text = "Medium"
'
'mnudif
'
Me.mnudif.Index = 2
Me.mnudif.Text = "Difficult"
'
'MenuItem1
'
Me.MenuItem1.Index = 2
Me.MenuItem1.Text = "Quit"
'
'lblc
'
Me.lblc.Location = New System.Drawing.Point(24, 368)
Me.lblc.Name = "lblc"
Me.lblc.Size = New System.Drawing.Size(64, 32)
Me.lblc.TabIndex = 0
Me.lblc.Text = "Credits"
'
'lblcredi
'
Me.lblcredi.Location = New System.Drawing.Point(112, 368)
Me.lblcredi.Name = "lblcredi"
Me.lblcredi.TabIndex = 1
Me.lblcredi.Text = "10"
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(0, Byte))
Me.Panel1.Location = New System.Drawing.Point(24, 32)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(336, 320)
Me.Panel1.TabIndex = 2
'
'lbltim
'
Me.lbltim.Location = New System.Drawing.Point(288, 368)
Me.lbltim.Name = "lbltim"
Me.lbltim.Size = New System.Drawing.Size(88, 32)
Me.lbltim.TabIndex = 3
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(216, 368)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(32, 32)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Time"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(392, 462)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.lbltim)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.lblcredi)
Me.Controls.Add(Me.lblc)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private component As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents mnuStart As System.Windows.Forms.MenuItem
Friend WithEvents lblcredit As System.Windows.Forms.Label
Friend WithEvents Timer2 As System.Windows.Forms.Timer
Friend WithEvents lbltime As System.Windows.Forms.Label
Friend WithEvents mnuhard As System.Windows.Forms.MenuItem
Friend WithEvents mnumed As System.Windows.Forms.MenuItem
Friend WithEvents mnueasy As System.Windows.Forms.MenuItem
Friend WithEvents mnudiff As System.Windows.Forms.MenuItem
Friend WithEvents Timer3 As System.Windows.Forms.Timer
Friend WithEvents Timer4 As System.Windows.Forms.Timer
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblc.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
init_game()
End Sub
Public Sub drawblock2(ByVal drawX As Integer, ByVal drawY As Integer, ByVal scope As Integer)
'declare graphics
Dim drawme As Graphics = Me.Panel1.CreateGraphics
drawme.Clear(Me.Panel1.BackColor)
'draw box
drawme.FillRectangle(Brushes.Green, New Rectangle(drawX * scope, drawY * scope, scope, scope))
End Sub
Private Sub timer1_tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
block2.moveblock(block2.dir)
drawblock2(block2.currentX, block2.currentY, block2.scope)
If block2.restart = True Then
mycredits -= 1
initialinterval = initialinterval * 0.9
Timer1.Interval = initialinterval
lblcredi.Text = mycredits
block2.restart = False
End If
If mycredits = 0 Then
Timer1.Enabled = False
Timer2.Enabled = False
MessageBox.Show("Too bad...The Game is Over")
End If
End Sub
Private Sub Form1_keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyValue
Case 37
block2.moveblock("L")
Case 38
block2.moveblock("U")
Case 39
block2.moveblock("R")
Case 40
block2.moveblock("D")
End Select
End Sub
Private Sub mnueas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnueas.Click
initialinterval = 2000
diffact = 1
mnudif.Checked = False
mnumed.Checked = False
mnueas.Checked = True
mnudif.Enabled = False
mnumed.Enabled = False
mnueas.Enabled = True
End Sub
Private Sub mnumedi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnumedi.Click
initialinterval = 1000
diffact = 2
mnudif.Checked = False
mnumed.Checked = True
mnueas.Checked = True
mnudif.Enabled = False
mnumed.Enabled = True
mnueas.Enabled = False
End Sub
Private Sub mnudif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnudif.Click
mnudif.Checked = True
mnumed.Checked = False
mnueas.Checked = True
initialinterval = 500
diffact = 3
mnudif.Enabled = True
mnumed.Enabled = False
mnueas.Enabled = False
End Sub
Private Sub mnustarts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnustarts.Click
Timer1.Enabled = True
Timer1.Interval = 1000
Timer2.Enabled = True
Timer1.Interval = initialinterval
'drawing by using drawblock2 and block2 information
drawblock2(block2.CurrentX, block2.CurrentY, block2.scope)
block2.dir = "R"
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
inttimer -= 1
lbltim.Text = inttimer
totaltime = totaltime + 1
If inttimer = 0 Then
Timer1.Enabled = False
Timer2.Enabled = False
MessageBox.Show("Too bad...The Game is Over")
End If
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
End
End Sub
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
Public Class Class2
'location of X & Y co-ordinates for the block currently
Public CurrentX As Integer
Public CurrentY As Integer
Public Scope As Integer
'To communicate with the user interface when the block is out of the range
Public Restart As Boolean
'Current Moving Direction
Public Dir As String
'When instance being created without any parameters
Public Sub New()
CurrentX = 0
CurrentY = 0
Scope = 0
End Sub
'When instance being created with initial parameters (X and Y location and the range)
Public Sub New(ByVal Xstart As Integer, ByVal Ystart As Integer, ByVal Sstart As Integer)
CurrentX = Xstart
CurrentY = Ystart
Scope = Sstart
End Sub
' A method to decide the movement of the block
Public Overridable Sub MoveBlock(ByVal Direction As String)
' To check if the block is out of the range
SetEnd()
' To sent a proper direction property
Dir = Direction
' To move right
If Direction = "R" Then
CurrentX += 1
End If
' To move left
If Direction = "L" Then
CurrentX -= 1
End If
'to move up
If Direction = "U" Then
CurrentY -= 1
End If
' To move down
If Direction = "D" Then
CurrentY += 1
End If
End Sub
' A method use to decide if the block is out of the range
Protected Sub SetEnd()
' Check if horizontally out of the range
If CurrentX > 13 Or CurrentX < 0 Then
MessageBox.Show("You lost a credit!")
Restart = True
CurrentX = 7
CurrentY = 7
End If
' Check if vertically out of the range
If CurrentY > 13 Or CurrentY < 0 Then
MessageBox.Show("You lost a credit!")
Restart = True
CurrentX = 7
CurrentY = 7
End If
End Sub
End Class
the following code are in class2:
Public Class Class2
'location of X & Y co-ordinates for the block currently
Public CurrentX As Integer
Public CurrentY As Integer
Public Scope As Integer
'To communicate with the user interface when the block is out of the range
Public Restart As Boolean
'Current Moving Direction
Public Dir As String
'When instance being created without any parameters
Public Sub New()
CurrentX = 0
CurrentY = 0
Scope = 0
End Sub
'When instance being created with initial parameters (X and Y location and the range)
Public Sub New(ByVal Xstart As Integer, ByVal Ystart As Integer, ByVal Sstart As Integer)
CurrentX = Xstart
CurrentY = Ystart
Scope = Sstart
End Sub
' A method to decide the movement of the block
Public Overridable Sub MoveBlock(ByVal Direction As String)
' To check if the block is out of the range
SetEnd()
' To sent a proper direction property
Dir = Direction
' To move right
If Direction = "R" Then
CurrentX += 1
End If
' To move left
If Direction = "L" Then
CurrentX -= 1
End If
'to move up
If Direction = "U" Then
CurrentY -= 1
End If
' To move down
If Direction = "D" Then
CurrentY += 1
End If
End Sub
' A method use to decide if the block is out of the range
Protected Sub SetEnd()
' Check if horizontally out of the range
If CurrentX > 13 Or CurrentX < 0 Then
MessageBox.Show("You lost a credit!")
Restart = True
CurrentX = 7
CurrentY = 7
End If
' Check if vertically out of the range
If CurrentY > 13 Or CurrentY < 0 Then
MessageBox.Show("You lost a credit!")
Restart = True
CurrentX = 7
CurrentY = 7
End If
End Sub
End Class
i still have some bugs and there some problems.