|
You create button the same way you create an instance of any other class, with New. You then set a bunch of properties on the button for size, location, Text, whatever, ... Then you add the button to the container form's Controls collection.
Dim newButton As New Button
newButton.Location = New Point(x, y)
newButton.Size = New Size(50, 75)
newButton.Text = someText
Me.Controls.Add(newButton)
Next, you have to wire up the button's Click event so you can get notified when the user clicks on it. That you do with the AddHandler statement:
AddHandler newButton.Click, AddressOf myButtonClickHandler
Of course, myButtonClickHandler has to have the signature of the appropriate event handler:
Private Sub myButtonClickHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
... code to handle the button click goes here
End Sub
Multiple buttons can be wired up to the same event handler.
|
|
|
|
|
how do i get it to make the right amount of buttons and name them all and put them in the right place
modified on Friday, May 9, 2008 2:16 PM
|
|
|
|
|
jacko873 wrote: how do i get it to make the right amount of buttons
Iterate over the returned rows in your datatable. One button for each row.
jacko873 wrote: put them in the right place
Simple math. All you have to do is calculate an offset from a fixed point multiplied by the count of buttons you've put down already.
|
|
|
|
|
Thank you Got the buttons working the names are right and the positions are great but I do have one last think to ask
How do I create an event for each button?
What I want the buttons to do is when they are clicked and an item to a list box and add the price to a variable for later
|
|
|
|
|
I already told you how to wire up the button's Click event.
|
|
|
|
|
I get that I can create event but each button has the same event
I what each event to be different dependant on the text of the button
|
|
|
|
|
Like was said before:
AddHandler newButton.Click, AddressOf myButtonClickHandler
but change myButtonClickHandler to the name of the method you want to be called onClick.
Edit:
pseudo code:
if button.text == string1 then
AddHandler newButton.Click, AddressOf myButtonClickHandler1
else if button.text == string2 then
AddHandler newButton.Click, AddressOf myButtonClickHandler2
etc etc
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
Then you have to cast the Sender object back to a button. You can then use it just like it was dropped on the form in the designer:
Dim b As Button = DirectCast(sender, Button)
|
|
|
|
|
Hi,
I need some help with a VBA script in Excel 2003, its probably really simple but the macro recorder hasnt been much use and im not sure how to start.
All I want to do is:
Check a worksheet value (i.e. in call A1), for the first value check on another worksheet list
>> If this value is in a row, delete this row and all rows containing this value, if not, do nothing and check the next record
Then move onto the next record (i.e. in cell C2) until there are no records left to check
How would I do this please (or can you give me advise on how to do something similar so I can make a start at finding a solution?).
Many thanks in advance
|
|
|
|
|
I won't write code for exactly what you need but I have got similar example.
Sub CheckList()
Sheet1.Cells(1, 1) = "Text1"
Sheet2.Cells(1, 1) = "Text1"
Dim sValueFromSheet1 As String
Dim sValueFromSheet2 As String
sValueFromSheet1 = Sheet1.Cells(1, 1)
sValueFromSheet2 = Sheet2.Cells(1, 1)
If sValueFromSheet1 = sValueFromSheet2 Then
Sheet1.Activate
Rows("1:1").Select
Selection.Delete Shift
Range("A1").Select
End If
End Sub
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Is there a way to read a datatable from an .xml file on disk such that the created datatable contains only a subset of the records in the .xml table? Something simlar to the select statement in SQL? Certainly seems like there should be, but I can't seem to find it.
Thanks
|
|
|
|
|
cstrader232 wrote: Is there a way to read a datatable from an .xml file on disk such that the created datatable contains only a subset of the records in the .xml table? Something simlar to the select statement in SQL? Certainly seems like there should be, but I can't seem to find it.
You can't find it because it doesn't exist. The DataTable/DataSet objects load the entire XML file. You don't have the option of selecting just the records you want. You'd have to write you own implementation of this, probably based on using an XmlReader, and build the datatable yourself. Implementing a query language would be the hardest part of doing this.
|
|
|
|
|
Thank you... I guess I should save these tables in a database.
Would you be willing to look at my question on reflection that i posted on May 7th?
|
|
|
|
|
cstrader232 wrote: Would you be willing to look at my question on reflection that i posted on May 7th?
I already am, in what little free time I have.
|
|
|
|
|
Hi,
I know this may not be the place to post this, but it is about syntax in VB, so I thought it would be the best place.
(P.s. This is a VERY simplified example of what I want to do... I wouldnt waste effort with linq on something this simple )
I have a list of structures in VB, and can easily select an item from the list:
Public Structure UserInfo
Public ID As Integer
Public Name As String
End Structure
Dim Users As New List(Of UserInfo)
Users.Add(New UserInfo With {.ID = 1, .Name="Jim"})
Users.Add(New UserInfo With {.ID = 2, .Name="Bob"})
Users.Add(New UserInfo With {.ID = 3, .Name="Sue"})
Now, what I want to do is update user ID 3 (for example) to change the name from Sue to Susan...
At the moment I use this:
Dim User As UserInfo = (From UserInfo In Users Where UserInfo.ID = 3 Select UserInfo).First
Users.Remove(User)
User.Name = "Susan"
Users.Add(User)
This works, but surely there is a better way? I have tried rooting through Google, but I am not sure of what I should be looking for to filter out all the Linq to sql and c# examples
Please help!
|
|
|
|
|
A structure should generally be immutable, and the point of using a structure is mostly defated as you have a reference type inside it. Use a class instead of a structure.
Public Class UserInfo
Public ID As Integer
Public Name As String
End Structure
Dim Users As New List(Of UserInfo)
Users.Add(New UserInfo With {.ID = 1, .Name="Jim"})
Users.Add(New UserInfo With {.ID = 2, .Name="Bob"})
Users.Add(New UserInfo With {.ID = 3, .Name="Sue"})
Now you don't have to remove and add the item to update it:
(From UserInfo In Users Where UserInfo.ID = 3 Select UserInfo).First.Name = "Susan"
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Guffa,
Thanks for the reply - some very useful information in there. I do have one small problem though - I cant find the correct syntax for the update:
(From UserInfo In Users Where UserInfo.ID = 3 Select UserInfo).First.Name = "Susan"
It doesnt work on its own in VB 2k8, and after hours of net searching, I cant find the answer . Using:
dim b as boolean = (From UserInfo In Users Where UserInfo.ID = 3 Select UserInfo).First.Name = "Susan"
compiles, but obviously doesnt update anything (the expression above supposedly returns a boolean)
If you get chance, and you know the answer, can you post a quick message telling me...
Ta muchly!
|
|
|
|
|
I thought that the LINQ expression could be used as an expression, but obviusly it can't. If you put the result in a variable, it works:
Dim user As UserInfo = (From u In Users Where u.ID = 3 Select u).First
user.Name = "Susan"
Another way to do this (and more effective as it only looks until it finds the first occurance) is to use a lambda expression:
Users.Find(Function(u) u.ID = 3).Name = "Susan"
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Guffa,
Thanks for that - you have been a huge help!
I cant believe I didnt try option 1 first though I think I tried everything but!
|
|
|
|
|
hi
in may project i exploit my data to exl sheet but the styel not very will because the size of the sill is smailer than data size
is their is way to make the sill size larger in my code not from the excel?
|
|
|
|
|
asha_s wrote: in may project i exploit my data to exl sheet but the styel not very will because the size of the sill is smailer than data size
It's "export my data", not "exploit".
asha_s wrote: but the styel not very will
Are you saying that the cell formatting isn't correct??
asha_s wrote: the size of the sill is smailer than data size
Are you saying the size of the CELL, not "sill", is too small to fit the width of the data?
asha_s wrote: is their is way to make the sill size larger in my code not from the excel
You can't do it in your file, but you can use the Excel object model to do this. You would need either the Visual Studio Tools for Office (recommended) or add a reference to the Excel x.x Object Model. This method requires that you have a good working knowledge of Excel and it's object model to do this.
|
|
|
|
|
Hi,
I was wondering, is there any way to execute code [a procedure, for example] at a specified system time [say 11:45:30] without having to use a timer to check system time every x seconds?
Thanks !
Kazz
"Users are there to click on things, not think. Let the archs do the damn thinking."
|
|
|
|
|
Ariel Kazeed wrote: without having to use a timer to check system time every x seconds?
Well, you could use the task scheduler in windows to run your app. If you use a timer, you can set it to first check every 12 hours, then every 8, etc, you can make the timer smaller as the interval to go is less.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello every one...
I just came across a property of picture box called initialimage... when i read the description it says "Image to be displayed while another image is loding"
I had a issue that when i am getting a image to be displayed from DB it is taking lot of time delay...
I taught may be by this property i can load a image saying "Loading Image.... " or something like that... that will make the application a lot more presentable...
But i am not able to use it
Can some one please help me with it
Regards
Nishkarsh
|
|
|
|
|
The property is just an image, so you'd load an image from the file system or resources and set that property. You can probalby also browse direct to an image on the file system in your designer and it will take care of it for you.
Where are you stuck ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|