|
{vb .net 2003}
I'd like to add controls (specifically labels) to a form when its resized, to have the most number of labels possible that fit on the screen. I haven't had much luck finding a tutorial or code snippet that does this. Controls would be created using a for or while loop, so i need some way to easily create lots of them. I have the resize event down fine, its the dynamic creation that I'd like help on.
Thanks in advance,
BAM
|
|
|
|
|
bamnet wrote: have the most number of labels possible that fit on the screen.
bamnet wrote: create lots of them
Personally, I think that's a bad idea. the more controls you have on a form the longer it'll take to show - consider users with lower-end machines.
The code you'd be needing would look something like this (out my head)
Dim MyLabel As Label 'declare at modular level
Private Sub CreateLabels()
'create a new instance of a label
MyLabel = New Label
'add formatting, positioning, event handlers, etc. here
Me.Controls.Add(MyLabel) 'add the label to the form.
End Sub
You'll probably have to write functions to return values of how many labels you'll need as well as where to position them.
|
|
|
|
|
I don't have to consider users with lower end machines very much. The application is going to be used on one or maybe 2 machines maximum. The idea is to create a few labels on a panel on the lefthand side based on the screen resolution. In my previous draft of this program everything was hardcoded and changing the resolution and size of the application meant rewriting it. The most labels would be 10 max.. not too bad I think.
I've tried that code an I can't get it to display the label, I know the spot on the form is clear and set visible to true.
|
|
|
|
|
You added the labels to the form. They're probably sitting behind your panel control. Add them to the Panel's Controls collection instead.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I agree, I have to add them to the panel.
Me.PanelL.Controls.Add(newButton)
accomplished this task
|
|
|
|
|
The next part is doing this with a loop. I can create one element and add it to the panel, but how would I create x number of them?
|
|
|
|
|
Looping is easy, the problem I think you'll encounter is not adding more than one label but determining how many too add.
Modifying the code above slightly to demonstrate the loop -
Dim MyLabel As Label 'declare at modular level
'pass the value of the number of labels you'll need to
'the CreateLabels sub
Private Sub CreateLabels(ByVal NumberOfLabels as Integer)
Dim i As Integer
Do Until i = NumberOfLabels
'create a new instance of a label
MyLabel = New Label
'add formatting, positioning, event handlers, etc. here
Me.PanelL.Controls.Add(MyLabel) 'add the label to the panel
i += 1 'increment i so as to avoid an infinite loop
Loop
End Sub
|
|
|
|
|
Hi everyone:
While digging down into the ADO.NET side of VB.NET I came across a nice little bit of code that allows me to return the schema of a database table.
Code snippet:
Private Sub Table_Schema(ByVal strTbl As String)
'Retrieving schema for columns from a single table
Dim cmd As OleDbCommand = New OleDbCommand(strTbl, objConnection)
cmd.CommandType = CommandType.TableDirect
Try
'Retrieve schema only
objConnection.Open()
'Dim reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SchemaOnly)
Dim reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.KeyInfo)
'Get references to schema information
Dim SchemaTable As DataTable = reader.GetSchemaTable()
'Close and release the connection before processing results
reader.Close()
objConnection.Close()
'Display schema table column headers
Dim col As DataColumn
SchemaTableList.View = View.Details
SchemaTableList.Clear()
For Each col In SchemaTable.Columns
SchemaTableList.Columns.Add(col.ColumnName, 100, HorizontalAlignment.Left)
Next
'Display Schema
Dim row As DataRow
Dim ColCount As Integer = SchemaTable.Columns.Count
For Each row In SchemaTable.Rows
Dim OrderDetails(ColCount) As String
Dim ColIdx As Integer
For ColIdx = 0 To ColCount - 1
OrderDetails(ColIdx) = Convert.ToString(row(ColIdx))
Next
Dim NewItem As ListViewItem = New ListViewItem(OrderDetails)
SchemaTableList.Items.Add(NewItem)
Next
Catch OleDbExceptionErr As OleDbException
'Display the error
MessageBox.Show(OleDbExceptionErr.Message, "Access SQL")
End Try
End Sub
The problem I have is; I don't need all that schema information. All I'm interested in is the Name of the Column, the datatype of the column and is it a primary column(field) or not.
In VB6 you could determine what information you wanted returned to you. My question is: Is there such a method available in VB.NET/ADO.NET? If so, How do you set it up for use?
Quecumber256
|
|
|
|
|
Hi
I am tryning to make aHi
I’m trying to make a program that prints out some text on a special location on a paper.
I’m using a Windows form, with some textboxes with a sender and resiver address.
Some combo boxes to determine a transport method, I made some text appear in a text box, when I check the combo box.
Example:
I check the box whose label is Taxi, and the word Taxi appears in a text box.
Then I made some buttons for the command printing, and for the command Exit (made a menu strip too, with the same functions).
My question then is how I can print this out.
I want to have the senders address on one location, and the resiver address on another location on the printed paper
And so on....
I’m using VB in visual studio 2005, and I’m going to print this out on a Oki Microline 520.
Ole Kr
A new beginner in VB.net
|
|
|
|
|
There are many ways to do what you ask...
Are you using a database to store information?
If so, it may have reporting features that you could use quite easily.
Would you consider Office automation, e.g. Word, Excel?
If so, you could simply create a Word template or Excel template and insert the data and print it from your code. This would require an installation of one of the above MS Office applications.
You could use Crystal Reports (if you have it).
Otherwise, you will need to work with Printer/Document objects, which could be quite difficult for someone new to VB.
Steve
|
|
|
|
|
Hii all,
I know this may seems to be a silly question but I need to know. Is it possible to delete an Executable file from itself. e.g I have an application, I want to delete its executable file from the code written in it.
Please reply.
Mubashir
|
|
|
|
|
No, you can't. The .EXE file remains locked open so long as the code in it is loaded into a process. You'll have to quit and have an external process delete this .EXE.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
is there a way that you could build an exe file into memory as a separate process and then have it wait for the parent process to die off and then delete it then end and kill itself from memory?
|
|
|
|
|
Well, you can load a new Assembly from an array of bytes, documented here[^]. The bytes can either be sourced from emitted code or from data in a file.
The problem is creating an entirely new Process out of that Assembly. I don't know how you can get from a loaded assembly to a whole new process.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi folks,
I'm in the process of writing an application to check for the existance of files and their sizes to replace a program we have at work which doesn't work (and which the source code has been lost).
Now I've recently started using Visual Basic 2005 Express Edition. I have a little bit of experience of VB6 but I'm struggling to get my head around the way some of the things are done in VB.Net.
The program is a console program which is supposed to sit in the background until a certain time and then start performing commands. I would like to add a couple of forms that can be used while the console application is running.
I found an example of code on a web site (can't remember the source sorry) which shows the form I want but then transfers execution to that form and stops running anything in the console window. The code I have is below...
<br />
Application.Run(New Form1())<br />
Now I would like the form to show on the screen and be active but also have things running in the background. I guess it would be classed as having two tasks running at once.
I'm just wondering if anyone knows how I can acheve this?
The idea is the end user can use things on the form while other tasks run on the console window in the background. At the moment though I can only have the console window doing something OR the form active, not both at the same time.
Sorry if this is a bit vague. I've spent the past hour searching Google but I can't seem to find anything obvious.
Could anyone suggest anything?
Regards,
Rob
|
|
|
|
|
You'd have to launch your forms on their own seperate threads. But, if you're going to use forms, you'd be better off starting from a Windows Forms app and including support for a console, instead of a Console app written trying to do forms.
It's easier to launch the Console portion of your app on it's own thread than it is to launch the Forms portion.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Ahh I see. Is it easy to open a console window from a Windows Forms app?
Thanks for the advice. Luckily I haven't got very far yet with the app so I'll start again with a new Windows Forms app.
Regards,
Rob
|
|
|
|
|
Try reading this[^] article for an example.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am written a program in VB.NET 2005 and have used Crystal Reports XI release 2 Developers Edition for reports. All working as expected.
My problem is that when I include the Crystal Reports Merge Modules into my Install Sheild project, package up and the run the MSI on a PC, the installer creates several folders in the root directory contain several files that relate to Crystal Reports.
These folders include html, css, images, js and prompting and seem to relate to some web functionality of Crystal. (Not that I require any web front end to my project).
Surely they should not install to the root folder? Can anyone point out my mistake?
Thanks
Steve Jowett
|
|
|
|
|
i maked visual basic component with a component class i add a texbox and modify some properties a methods and know i wan to know how can i make a .dll from this component because i want to add it to my tool tabs. ????
Mago R. Vasquez (Gbyte)
|
|
|
|
|
Did you build it as part of a windows class library?
If so, locate "Build" on the VS menu bar, click on it & then click on "Build solution". You'll find the dll in the solution bin folder.
|
|
|
|
|
How Can I Get Cpu Name???
|
|
|
|
|
FriendlySoluations wrote: How Can I Get Cpu Name???
Me.Text = System.Environment.MachineName
Hope this helps
clanguage
|
|
|
|
|
I think he mean the name of the actual CPU, not the name of the machine in which the CPU resides.
|
|
|
|
|
Colin Angus Mackay wrote: How Get Cpu Name
You might be right. I never thought about the chip.
clanguage
|
|
|
|