473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to use a button handler and move a button in an array

i have this code that i have been trying to make it so i could move the buttons in the array( the locations of the buttons) but i am not able to move the buttons like i am if i just have a normal button
Code:
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim point As New System.Drawing.Point
  3.     Dim X, Y As Integer
  4.     Dim buttons(3, 3) As Button
  5.     Dim times As Integer = 0
  6.     Structure matching
  7.         Dim question As String
  8.         Dim answers() As String
  9.  
  10.         Dim correctAswr As Integer
  11.     End Structure
  12.     Dim match(11) As matching
  13.  
  14.  
  15.  
  16.     Dim gridSize As Integer = 3
  17.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  18.  
  19.     End Sub
  20.  
  21.     'Private Sub Button1_MouseClick(sender As Object, e As MouseEventArgs) Handles Button1.MouseClick
  22.     '    X = Control.MousePosition.X - Button1.Location.X
  23.     '    Y = Control.MousePosition.Y - Button1.Location.Y
  24.     'End Sub
  25.  
  26.     'Private Sub Button1_MouseDown(sender As Object, e As MouseEventArgs) Handles Button1.MouseDown
  27.  
  28.     'End Sub
  29.  
  30.     'Private Sub Button1_MouseMove(sender As Object, e As MouseEventArgs) Handles Button1.MouseMove
  31.     '    If e.Button = Windows.Forms.MouseButtons.Right Then
  32.     '        ContextMenuStrip = Nothing
  33.  
  34.     '        point = Control.MousePosition
  35.     '        point.X = point.X + (X)
  36.     '        point.Y = point.Y + (Y)
  37.     '        Button1.Location = point
  38.  
  39.     '    End If
  40.  
  41.     'End Sub
  42.  
  43.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  44.         Dim buffer As Integer = 0
  45.         Dim buttonSize As Integer = 87.45
  46.         For i = 0 To gridSize - 1 'makes the button
  47.             For j = 0 To gridSize - 1
  48.                 buttons(i, j) = New Button
  49.                 buttons(i, j).Left = buffer + (buffer + buttonSize) * j
  50.                 buttons(i, j).Top = buffer + (buffer + buttonSize) * i
  51.                 buttons(i, j).Height = buttonSize
  52.                 buttons(i, j).Width = buttonSize
  53.                 buttons(i, j).Tag = i & times & j
  54.                 times = times + 1
  55.                 buttons(i, j).Text = "$ " '& Clues(j).money
  56.                 Me.Controls.Add(buttons(i, j))
  57.                 AddHandler buttons(i, j).Click, AddressOf buttonclick
  58.                 AddHandler buttons(i, j).Click, AddressOf Button_Mouseclick
  59.                 AddHandler buttons(i, j).Click, AddressOf Button_MouseMove
  60.             Next
  61.         Next
  62.     End Sub
  63.  
  64.  
  65.     Sub buttonclick(sender As Button, e As EventArgs)
  66.  
  67.         Dim row As Integer = Integer.Parse(sender.Tag.ToString.Chars(0))
  68.         Dim column As Integer = Integer.Parse(sender.Tag.ToString.Chars(2))
  69.  
  70.     End Sub
  71.  
  72.  
  73.     Sub Button_Mouseclick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
  74.  
  75.         X = Control.MousePosition.X - Me.Location.X
  76.         Y = Control.MousePosition.Y - Me.Location.Y
  77.     End Sub
  78.  
  79.     Private Sub Button_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
  80.  
  81.         If e.Button = Windows.Forms.MouseButtons.Right Then
  82.             ContextMenuStrip = Nothing
  83.  
  84.             point = Control.MousePosition
  85.             point.X = point.X + (X)
  86.             point.Y = point.Y + (Y)
  87.             Me.Location = point
  88.  
  89.         End If
  90.     End Sub
  91. End Class
May 18 '16 #1
0 1030

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Matt | last post by:
I want to understand the difference between submit button and regular button: <input type="submit"> and <input type="button">. My understanding is that submit button will send the entire HTML form...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
8
by: frankcvc | last post by:
I created a control array at runtime using the following code. I also wanted to code the controlarray click event. My code can respond to click event but cannot identify the specific control...
2
by: Newbie | last post by:
i have a c# asp.net webform that has a "Close" button. When the user clicks the Close button, a message box saying "do u want to save to database...?". the problem is that the statements inside the...
0
by: Novice | last post by:
Hey all, I've already posted this question and two posters offered suggestions and they worked - but now I would like to know why - and if possible the answer to a second question. Here is my...
3
by: Mel | last post by:
Hi, Is there any way I can force to change button background colour when toggle button is checked? Just like button change its background colour when mouseover in MS Visual Studio.NET. I hope I...
1
by: Bill_W_Stephens | last post by:
I need a form with two buttons and ability to detect which button was pressed. I got this code to work using a javascript global variable, but I know there must be a better way using DOM. Any...
3
by: swartzbill2000 | last post by:
Hello, I have an array of Buttons down a column of a TableLayoutPanel. They all share a common click handler. In the handler, how can I determine the row of the TableLayoutPanel for the Button...
1
by: kristu | last post by:
Hi i have a button array of . know i want that when i press a button, i get the location of the button in the array, not which button is pressed but the location.I used the sender to do a...
1
by: Drummin | last post by:
How do I get user id from radio button name in an array. The value is a variable. So this section repeats in an array and when submitting the ID and value is passed for each user in the array. echo...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.