Creating handle in a Windows Form with a declared object as an arrayprgress bar when proccessing update application VB NETVB.net random numbers each to different labelVB.NET System32 Path FileNotFoundExceptionWhy Excel Data not displayed complete in DataGrid in VB.NET?how to insert checked items from checkedlistbox to SQL database?How do I run CMD.exe as administratorChanging background color using combobox from a different form in Visual BasicConvert listbox to DataGridViewHow to inherit a form class to another form and is it even possible?I need help my CMD working not the same result
History of the kernel of a homomorphism?
Install LibreOffice-Writer Only not LibreOffice whole package
Why am I receiving the identity insert error even after explicitly setting IDENTITY_INSERT ON and using a column list?
Can my 2 children, aged 10 and 12, who are US citizens, travel to the USA on expired American passports?
Why would a military not separate its forces into different branches?
Where to draw the line between quantum mechanics theory and its interpretation(s)?
Are there terms in German for different skull shapes?
Is there a word that describes the unjustified use of a more complex word?
Checking if two expressions are related
Copy previous line to current line from text file
How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?
Handling Null values (and equivalents) routinely in Python
How to pass hash as password to ssh server
Would you use "llamarse" for an animal's name?
How do I calculate how many of an item I'll have in this inventory system?
Correct way of drawing empty, half-filled and fully filled circles?
What to use instead of cling film to wrap pastry
Are the Night's Watch still required?
What is the closest airport to the center of the city it serves?
SOQL query WHERE filter by specific months
Trigonometry substitution issue with sign
Will 700 more planes a day fly because of the Heathrow expansion?
How does the reduce() method work in Java 8?
Are pressure-treated posts that have been submerged for a few days ruined?
Creating handle in a Windows Form with a declared object as an array
prgress bar when proccessing update application VB NETVB.net random numbers each to different labelVB.NET System32 Path FileNotFoundExceptionWhy Excel Data not displayed complete in DataGrid in VB.NET?how to insert checked items from checkedlistbox to SQL database?How do I run CMD.exe as administratorChanging background color using combobox from a different form in Visual BasicConvert listbox to DataGridViewHow to inherit a form class to another form and is it even possible?I need help my CMD working not the same result
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Im trying to make a Connect 4 game just to practice some windows forms which im new to. What my code does is creates a grid of 7 x 6 regularly spaces blank PictureBox's. But since im creating them in the script and not using the form1 design windows i dont know how i would add Handles to them, especially since the PictureBox's are in an array. Any ideas?
Public Class Form1
Dim Grid(6, 5) As PictureBox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Visible = False
Me.FormBorderStyle = FormBorderStyle.FixedSingle
For i As Integer = 0 To 6
For j As Integer = 0 To 5
Grid(i, j) = New PictureBox
Grid(i, j).BackColor = Color.LightGray
Grid(i, j).Size = New Size(90, 90)
Grid(i, j).Location = New Point((i * 100) + 10, (j * 100) + 10)
Grid(i, j).Visible = True
Controls.Add(Grid(i, j))
Next
Next
End Sub
Private Sub Grid_MouseHover(sender As Object, e As EventArgs) Handles Grid(x, y).MouseHover 'Doesnt work
'Run depending on which picturebox in array
End Sub
End Class
I can get an error which is "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."
vb.net
add a comment |
Im trying to make a Connect 4 game just to practice some windows forms which im new to. What my code does is creates a grid of 7 x 6 regularly spaces blank PictureBox's. But since im creating them in the script and not using the form1 design windows i dont know how i would add Handles to them, especially since the PictureBox's are in an array. Any ideas?
Public Class Form1
Dim Grid(6, 5) As PictureBox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Visible = False
Me.FormBorderStyle = FormBorderStyle.FixedSingle
For i As Integer = 0 To 6
For j As Integer = 0 To 5
Grid(i, j) = New PictureBox
Grid(i, j).BackColor = Color.LightGray
Grid(i, j).Size = New Size(90, 90)
Grid(i, j).Location = New Point((i * 100) + 10, (j * 100) + 10)
Grid(i, j).Visible = True
Controls.Add(Grid(i, j))
Next
Next
End Sub
Private Sub Grid_MouseHover(sender As Object, e As EventArgs) Handles Grid(x, y).MouseHover 'Doesnt work
'Run depending on which picturebox in array
End Sub
End Class
I can get an error which is "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."
vb.net
You must use the AddHandler statement.
– Hans Passant
Mar 23 at 1:02
1
My question, why are you creating them in code in the first place? You know how many there will be and you know where they will be placed so why would you not add them in the designer? There's no point creating new ones over the course of a session because you can just clear the existing ones. It makes no sense to create them in code so you're trying to solve a problem that you created in the first place.
– jmcilhinney
Mar 23 at 1:15
add a comment |
Im trying to make a Connect 4 game just to practice some windows forms which im new to. What my code does is creates a grid of 7 x 6 regularly spaces blank PictureBox's. But since im creating them in the script and not using the form1 design windows i dont know how i would add Handles to them, especially since the PictureBox's are in an array. Any ideas?
Public Class Form1
Dim Grid(6, 5) As PictureBox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Visible = False
Me.FormBorderStyle = FormBorderStyle.FixedSingle
For i As Integer = 0 To 6
For j As Integer = 0 To 5
Grid(i, j) = New PictureBox
Grid(i, j).BackColor = Color.LightGray
Grid(i, j).Size = New Size(90, 90)
Grid(i, j).Location = New Point((i * 100) + 10, (j * 100) + 10)
Grid(i, j).Visible = True
Controls.Add(Grid(i, j))
Next
Next
End Sub
Private Sub Grid_MouseHover(sender As Object, e As EventArgs) Handles Grid(x, y).MouseHover 'Doesnt work
'Run depending on which picturebox in array
End Sub
End Class
I can get an error which is "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."
vb.net
Im trying to make a Connect 4 game just to practice some windows forms which im new to. What my code does is creates a grid of 7 x 6 regularly spaces blank PictureBox's. But since im creating them in the script and not using the form1 design windows i dont know how i would add Handles to them, especially since the PictureBox's are in an array. Any ideas?
Public Class Form1
Dim Grid(6, 5) As PictureBox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Visible = False
Me.FormBorderStyle = FormBorderStyle.FixedSingle
For i As Integer = 0 To 6
For j As Integer = 0 To 5
Grid(i, j) = New PictureBox
Grid(i, j).BackColor = Color.LightGray
Grid(i, j).Size = New Size(90, 90)
Grid(i, j).Location = New Point((i * 100) + 10, (j * 100) + 10)
Grid(i, j).Visible = True
Controls.Add(Grid(i, j))
Next
Next
End Sub
Private Sub Grid_MouseHover(sender As Object, e As EventArgs) Handles Grid(x, y).MouseHover 'Doesnt work
'Run depending on which picturebox in array
End Sub
End Class
I can get an error which is "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."
vb.net
vb.net
asked Mar 23 at 0:57
foxfox
54
54
You must use the AddHandler statement.
– Hans Passant
Mar 23 at 1:02
1
My question, why are you creating them in code in the first place? You know how many there will be and you know where they will be placed so why would you not add them in the designer? There's no point creating new ones over the course of a session because you can just clear the existing ones. It makes no sense to create them in code so you're trying to solve a problem that you created in the first place.
– jmcilhinney
Mar 23 at 1:15
add a comment |
You must use the AddHandler statement.
– Hans Passant
Mar 23 at 1:02
1
My question, why are you creating them in code in the first place? You know how many there will be and you know where they will be placed so why would you not add them in the designer? There's no point creating new ones over the course of a session because you can just clear the existing ones. It makes no sense to create them in code so you're trying to solve a problem that you created in the first place.
– jmcilhinney
Mar 23 at 1:15
You must use the AddHandler statement.
– Hans Passant
Mar 23 at 1:02
You must use the AddHandler statement.
– Hans Passant
Mar 23 at 1:02
1
1
My question, why are you creating them in code in the first place? You know how many there will be and you know where they will be placed so why would you not add them in the designer? There's no point creating new ones over the course of a session because you can just clear the existing ones. It makes no sense to create them in code so you're trying to solve a problem that you created in the first place.
– jmcilhinney
Mar 23 at 1:15
My question, why are you creating them in code in the first place? You know how many there will be and you know where they will be placed so why would you not add them in the designer? There's no point creating new ones over the course of a session because you can just clear the existing ones. It makes no sense to create them in code so you're trying to solve a problem that you created in the first place.
– jmcilhinney
Mar 23 at 1:15
add a comment |
1 Answer
1
active
oldest
votes
One possible way would be to set the .Tag
property using the coordinates -
add something like into your For..Next
loop
Grid(i, j).Tag = i.ToString & j.ToString
and use
AddHandler Grid(i, j).MouseHover, AddressOf Grid_MouseHover
and add this after the one above.
Then, change the first line of your MouseHover
Sub to
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
with no handler on the end.
Finally, change the type of the sender to a PictureBox
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
Dim Pbox As PictureBox = CType(sender, PictureBox)
Dim i As Integer = Integer.Parse(Pbox.Tag.ToString(0))
Dim j As Integer = Integer.Parse(Pbox.Tag.ToString(1))
End Sub
To access the Picturebox
and its properties, just use PBox
and if you need the coordinates, use i
and j
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309593%2fcreating-handle-in-a-windows-form-with-a-declared-object-as-an-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One possible way would be to set the .Tag
property using the coordinates -
add something like into your For..Next
loop
Grid(i, j).Tag = i.ToString & j.ToString
and use
AddHandler Grid(i, j).MouseHover, AddressOf Grid_MouseHover
and add this after the one above.
Then, change the first line of your MouseHover
Sub to
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
with no handler on the end.
Finally, change the type of the sender to a PictureBox
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
Dim Pbox As PictureBox = CType(sender, PictureBox)
Dim i As Integer = Integer.Parse(Pbox.Tag.ToString(0))
Dim j As Integer = Integer.Parse(Pbox.Tag.ToString(1))
End Sub
To access the Picturebox
and its properties, just use PBox
and if you need the coordinates, use i
and j
add a comment |
One possible way would be to set the .Tag
property using the coordinates -
add something like into your For..Next
loop
Grid(i, j).Tag = i.ToString & j.ToString
and use
AddHandler Grid(i, j).MouseHover, AddressOf Grid_MouseHover
and add this after the one above.
Then, change the first line of your MouseHover
Sub to
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
with no handler on the end.
Finally, change the type of the sender to a PictureBox
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
Dim Pbox As PictureBox = CType(sender, PictureBox)
Dim i As Integer = Integer.Parse(Pbox.Tag.ToString(0))
Dim j As Integer = Integer.Parse(Pbox.Tag.ToString(1))
End Sub
To access the Picturebox
and its properties, just use PBox
and if you need the coordinates, use i
and j
add a comment |
One possible way would be to set the .Tag
property using the coordinates -
add something like into your For..Next
loop
Grid(i, j).Tag = i.ToString & j.ToString
and use
AddHandler Grid(i, j).MouseHover, AddressOf Grid_MouseHover
and add this after the one above.
Then, change the first line of your MouseHover
Sub to
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
with no handler on the end.
Finally, change the type of the sender to a PictureBox
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
Dim Pbox As PictureBox = CType(sender, PictureBox)
Dim i As Integer = Integer.Parse(Pbox.Tag.ToString(0))
Dim j As Integer = Integer.Parse(Pbox.Tag.ToString(1))
End Sub
To access the Picturebox
and its properties, just use PBox
and if you need the coordinates, use i
and j
One possible way would be to set the .Tag
property using the coordinates -
add something like into your For..Next
loop
Grid(i, j).Tag = i.ToString & j.ToString
and use
AddHandler Grid(i, j).MouseHover, AddressOf Grid_MouseHover
and add this after the one above.
Then, change the first line of your MouseHover
Sub to
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
with no handler on the end.
Finally, change the type of the sender to a PictureBox
Private Sub Grid_MouseHover(sender As Object, e As EventArgs)
Dim Pbox As PictureBox = CType(sender, PictureBox)
Dim i As Integer = Integer.Parse(Pbox.Tag.ToString(0))
Dim j As Integer = Integer.Parse(Pbox.Tag.ToString(1))
End Sub
To access the Picturebox
and its properties, just use PBox
and if you need the coordinates, use i
and j
edited Mar 25 at 16:09
fox
54
54
answered Mar 23 at 14:45
David WilsonDavid Wilson
3,91821326
3,91821326
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309593%2fcreating-handle-in-a-windows-form-with-a-declared-object-as-an-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You must use the AddHandler statement.
– Hans Passant
Mar 23 at 1:02
1
My question, why are you creating them in code in the first place? You know how many there will be and you know where they will be placed so why would you not add them in the designer? There's no point creating new ones over the course of a session because you can just clear the existing ones. It makes no sense to create them in code so you're trying to solve a problem that you created in the first place.
– jmcilhinney
Mar 23 at 1:15