Scrolling text in form title bar - vb.net

I have written a simple code to scroll the text in the title bar of the form. It is working fine till the length of the text reach 159. After that the text cuts of in the title bar . It does not reach the end of the title bar rather cuts off in the middle of the title bar. Why does this happen?
tempheader is a variable that stores the me.text value at form load.
This is the code in the timer tick event with an interval of 100
Me.Text = " " & Me.Text
If Len(Me.Text) = 159 Then Me.Text = tempheader

Try this ..
Dim g As Graphics = Me.CreateGraphics()
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static sPace As String
sPace &= " "
Me.Text = sPace & Me.Text
If g.MeasureString(Me.Text, Me.Font).Width >= Me.Width Then
Me.Text = tempheader
sPace = ""
End If
End Sub

Lol I know this is an old post but I came across it whilst looking for something else anyway I just use a custom titlebar for scrolling text. Just create an empty form, doubleclick it delete all of the code and add the code from below. Go back and delete the form from the project and save it as a dll. You just need to import it back and add it to your toolbar and you can use it in any projects.
Imports System.Drawing
Public Class CustomTitlebar
Inherits Windows.Forms.Panel
Public Sub ColourTitleText(ByRef panelBG As Color, ByRef txtBG As Color, ByRef txtFC As Color)
Dim textbox1 As New Windows.Forms.TextBox
Dim Psize As New Point(26, 200)
Me.Size = New Point(26, 200)
Me.BackColor = panelBG
Me.BorderStyle = Windows.Forms.BorderStyle.None
Me.Dock = Windows.Forms.DockStyle.Top
Me.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
textbox1.Name = "Textbox1"
textbox1.BackColor = txtBG
If Not txtFC = Nothing Then
textbox1.ForeColor = txtFC
End If
textbox1.BorderStyle = Windows.Forms.BorderStyle.None
textbox1.Size = New Size(Psize.X - 4, 20)
textbox1.Location = New Point(3, 3)
textbox1.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
textbox1.Multiline = False
textbox1.Text = "Coded by tHE_alCHMist 2010"
Me.Controls.Add(textbox1)
End Sub
End Class
Put this in a timer "CustomTitlebar1.Text = MarqueeLeft(CustomTitlebar1.Text)"
and then put this function somewhere
Public Function MarqueeLeft(ByVal Text As String)
Dim Str1 As String = Text.Remove(0, 1)
Dim Str2 As String = Text(0)
Return Str1 & Str2
End Function
Finally remember to dock it with the top of the form and I hope someone finds this code useful.

Related

moving many controls together to represent a Seating Chart in VB.NET

Greetings,
I want To create a graphic representation of a seating chart (could be in a wedding venue or in cars...). I used a splitted panel, in the splittedPanel1 i put the buttons to create the cars, and inside the splitted panel2 i want to put the graphic representation. Inside SplittedPanel2, I've created a panel and a pictureBox (to represent some fixed areas in the real world).
I've also created a class called SimpleCar. SimpleCar is composed of 5 TextBox (es) and a PictureBox all in a panel to represent a car: the textBoses represent the passengers names and the car label, and the pictureBox to put an image representing a car (or a table). I've also made a sub to Add dynamically a SimpleCar.
2 problems occur when i want to move this new panel (dynamically created), using MouseDown and MouseUp events:
- first pb: while moving the existing panel, the screen flashes and the movement is not smooth
- second pb: i can't move a panel dynamically created
Note that moving a PictureBox by this code is very smooth but moving a panel is not user friendly.
I expect moving a dynamically created a panel smoothly, or should I reconsider displaying the cars in another way than in a panel?
Knowing that the final purpose of the code is to export a picture of all the created tables in the venue. I also tested the code with a groupBox and the results aren't good.
The simpleCar class is described in the code below:
Class SimpleCar
Public carNameBox, passengerNameBox1, passengerNameBox2,
passengerNameBox3, passengerNameBox4 As TextBox
Public carPictureBox As PictureBox
Public carGroup As Panel
Public Sub New()
carGroup = New Panel
carNameBox = New TextBox With {.Text = "carNmBx",
.BackColor = Color.Yellow,
.Name = "carNmBx"}
passengerNameBox1 = New TextBox With {.Text = "txtPassNmBx1",
.BackColor = Color.BlanchedAlmond,
.Name = "TextBox1"}
passengerNameBox2 = New TextBox With {.Text = "txtPassNmBx2",
.BackColor = Color.AliceBlue,
.Name = "TextBox2"}
passengerNameBox3 = New TextBox With {.Text = "txtPassNmBx3",
.BackColor = Color.Azure,
.Name = "TextBox3"}
passengerNameBox4 = New TextBox With {.Text = "txtPassNmBx4",
.BackColor = Color.Cyan,
.Name = "TextBox4"}
carPictureBox = New PictureBox With {.Text = "picBx1",
.BackColor = Color.BlanchedAlmond,
.Name = "picBox1"}
Dim fdialog As New OpenFileDialog()
fdialog.FileName = String.Empty
fdialog.Multiselect = True
If fdialog.ShowDialog = DialogResult.OK Then
If fdialog.FileNames.Length = 2 Then
carPictureBox.Image = Image.FromFile(fdialog.FileNames(0))
ElseIf fdialog.FileNames.Length = 1 Then
carPictureBox.Image = Image.FromFile(fdialog.FileName)
End If
End If
carGroup.Controls.Add(carPictureBox)
carGroup.Controls.Add(carNameBox)
carGroup.Controls.Add(passengerNameBox1)
carGroup.Controls.Add(passengerNameBox2)
carGroup.Controls.Add(passengerNameBox3)
carGroup.Controls.Add(passengerNameBox4)
End Sub
End Class
To Add dynamically a SimpleCar in the code below:
Public Sub Add_car()
Dim carType As SimpleCar
carType = New SimpleCar
Dim carPs1 = carType.passengerNameBox1
Dim carPs2 = carType.passengerNameBox2
Dim carPs3 = carType.passengerNameBox3
Dim carPs4 = carType.passengerNameBox4
Dim carNm = carType.carNameBox
Dim carPic = carType.carPictureBox
Dim carGroupBox = carType.carGroup
SplitContainer1.Panel2.Controls.Add(carGroupBox)
End Sub
So the problem occurs when i use this code to move a panel (if you replace PictureBox by Panel, even GroupBox) (it worked fine when I wanted to move one control: PictureBox1 in this sample):
'Drag To move PictureBox1 along with mouse-------------------------------------------
Dim oldX As Short
Dim oldY As Short
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
Dim X As Single = e.X
Dim Y As Single = e.Y
PictureBox1.Cursor = Cursors.SizeAll
oldX = CShort(X)
oldY = CShort(Y)
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseUp
Dim X As Single = e.X
Dim Y As Single = e.Y
PictureBox1.Cursor = Cursors.Default
End Sub
' to limit the movement within the app----------------------------------
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then
Dim ProposedLocation As New Point(PictureBox1.Left - (oldX - e.X), PictureBox1.Top - (oldY - e.Y))
PictureBox1.Left = CInt(IIf(ProposedLocation.X < 0, 0, IIf(ProposedLocation.X > SplitContainer1.Panel2.Width - PictureBox1.Width, SplitContainer1.Panel2.Width - PictureBox1.Width, ProposedLocation.X)))
PictureBox1.Top = CInt(IIf(ProposedLocation.Y < 0, 0, IIf(ProposedLocation.Y > SplitContainer1.Panel2.Height - PictureBox1.Height, SplitContainer1.Panel2.Height - PictureBox1.Height, ProposedLocation.Y)))
End If
End Sub

how to add some textbox with Code

i have trouble with this
Click Here for picture
The Code
Dim Tex1 As TextBox = Nothing
Dim Tex2 As TextBox = Nothing
Tex1 = New Windows.Forms.TextBox
Tex1.Name = "TextBox"
Tex1.Location = New System.Drawing.Point(12, 119)
Tex1.Size = TextBox1.Size
Tex1.TabIndex = 4
Tex2 = New Windows.Forms.TextBox
Tex2.Name = "TextBox"
Tex2.Location = New System.Drawing.Point(110, 119)
Tex2.Size = TextBox2.Size
Tex2.TabIndex = 5
Me.Controls.Add(Tex1)
Me.Controls.Add(Tex2)
i want to add the new textbox with clicking the picture box, like this
Click Here for Picture
but when i click the "add Picture Box" the textbox not appear
please, anyone help me ?
If you want to have the ability to add textboxes to your form then this is what you should do. First you will need to identify the button that you are going to use for this insertion event. I would assume the green plus symbol.
Then I would create a mouse event action like this:
Public Sub Mouse_Click(sender As Object, e As EventArgs) Handles MyButton.Click
' Some action...
End Sub
From there you will be able to insert your code into the click event like this:
Public Sub Mouse_Click(sender As Object, e As EventArgs) Handles MyButton.Click
Dim Tex1 As TextBox = Nothing
Dim Tex2 As TextBox = Nothing
Tex1 = New Windows.Forms.TextBox
Tex1.Name = "TextBox"
Tex1.Location = New System.Drawing.Point(12, 119)
Tex1.Size = TextBox1.Size
Tex1.TabIndex = 4
Tex2 = New Windows.Forms.TextBox
Tex2.Name = "TextBox"
Tex2.Location = New System.Drawing.Point(110, 119)
Tex2.Size = TextBox2.Size
Tex2.TabIndex = 5
Me.Controls.Add(Tex1)
Me.Controls.Add(Tex2)
End Sub
Now there is still a big issue with this code, the location of the textboxes. The reason this is an issue is because they are static, meaning they will always appear in the same spot so, one solution is to declare a global Point() to maintain the location of the newest textbox like this:
Dim tbLocation1 As Point = New Point(12, 199)
Dim tbLocation2 As Point = New Point(110, 199)
From there all you would then need to do is have some sort of margin amount that you want to move the textboxes by like this:
Dim marginAmt As Int32 = 30
Now that all of the pieces are present lets put it together:
Dim tbLocation1 As Point = New Point(12, 199)
Dim tbLocation2 As Point = New Point(110, 199)
Dim marginAmt As Int32 = 30
Public Sub Mouse_Click(sender As Object, e As EventArgs) Handles MyButton.Click
Dim Tex1 As TextBox = New Windows.Forms.TextBox
Dim Tex2 As TextBox = New Windows.Forms.TextBox
' Modifies Tex1
Tex1.Name = "TextBox"
Tex1.Location = tbLocation1
Tex1.Size = TextBox1.Size
Tex1.TabIndex = 4
' Modifies Tex2
Tex2.Name = "TextBox"
Tex2.Location = tbLocation2
Tex2.Size = TextBox2.Size
Tex2.TabIndex = 5
' Updates form
Me.Controls.Add(Tex1)
Me.Controls.Add(Tex2)
' Updates the point locations
tbLocation1 = New Point(tbLocation1.X, tbLocation1.Y + marginAmt)
tbLocation2 = New Point(tbLocation2.X, tbLocation2.Y + marginAmt)
End Sub
Now you just need to connect this event action to the button that you desire.

Winforms custom loading screen text not loading

I'm using VB.NET winforms and have a particular form that take a while to load up so I've decided to implement a loading screen to make it feel a bit less freezey. Here is the code I'm using in my freezey form load.
Private Sub HanleyView_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim loaderForm As New Loader
loaderForm.Show()
AllOpenOrdersList.FullRowSelect = True
NeedsAttentionList.FullRowSelect = True
StockManagementList.FullRowSelect = True
Dim lowStockCount = HelperMethods.ReviewLowStock()
ReviewLowStockButton.Text = "Review Low Stock (" & lowStockCount & ")"
RefreshAllOpenOrdersList()
RefreshNeedsAttentionList()
RefreshStockManagementList()
loaderForm.Close()
End Sub
So I start by showing the loading form and finish by closing it.
The good new is that the loading form appears, but the bad news is the "LOADING..." text which is a label on my loading form doesn't show, I just get a white patch there instead. I've tried two approaches, the above and calling Loader.Show and Loader.Close. I've also tried setting loaderForm.Label1.Text = "LOADING..." but this didn't make any difference. Each time the form loads (and the title loads which says "Loading please wait") but not the label on the form itself.
I've now also tried:
Dim loaderForm As New Loader
Dim lbl As New Label
loaderForm.Controls.Add(lbl)
lbl.Text = "LOADING..."
lbl.Location = New System.Drawing.Point(42, 21)
loaderForm.Show()
AllOpenOrdersList.FullRowSelect = True
NeedsAttentionList.FullRowSelect = True
StockManagementList.FullRowSelect = True
Dim lowStockCount = HelperMethods.ReviewLowStock()
ReviewLowStockButton.Text = "Review Low Stock (" & lowStockCount & ")"
RefreshAllOpenOrdersList()
RefreshNeedsAttentionList()
RefreshStockManagementList()
loaderForm.Close()
But this hasn't worked either.
EDIT: I've tried Varocarbas' code but was still unsuccessful. The form loads but the text remains a white patch
Dim loaderForm As Form = New Form
With loaderForm
.Height = 200
.Width = 300
.Location = New System.Drawing.Point(12, 12)
End With
Dim label1 As Label = New Label
loaderForm.Controls.Add(label1)
With label1
.Text = "LOADING..."
.Location = New System.Drawing.Point(12, 45)
End With
loaderForm.Show()
EDIT 2: For clarity, here is my code now it is working using Franck suggestion
Private Sub HanleyView_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim loaderForm As New Loader
loaderForm.Show()
Application.DoEvents()
AllOpenOrdersList.FullRowSelect = True
NeedsAttentionList.FullRowSelect = True
StockManagementList.FullRowSelect = True
Dim lowStockCount = HelperMethods.ReviewLowStock()
ReviewLowStockButton.Text = "Review Low Stock (" & lowStockCount & ")"
RefreshAllOpenOrdersList()
RefreshNeedsAttentionList()
RefreshStockManagementList()
loaderForm.Close()
End Sub
I have kept my original code and simply added Application.DoEvents() below loaderform.Show and it works properly now.
Also the below screenshot is what I mean by using the designer (and not doing it programmtically):
Multithreading!
Create and run the loaderForm on a separate thread. But then you need to be careful about cross-thread operations, so have a self-invoking method on your loaderForm, such as:
Public Sub ParseStatus(msg as String)
If Me.InvokeRequired Then Me.Invoke(New Action(Of String)(AddressOf Me.ParseStatus), msg) Else Me.Label1.Text = msg
End Sub
Also in your loaderForm you want something like:
Public Sub Finish()
Me.DialogResult = Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Then in the Load procedure of your form:
Private Sub HanleyView_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim loaderForm As New Loader
Dim loaderThread As New Threading.Thread(New Threading.ThreadStart(AddressOf loaderForm.ShowDialog))
loaderThread.Start()
loaderForm.ParseStatus("Loading ...")
AllOpenOrdersList.FullRowSelect = True
NeedsAttentionList.FullRowSelect = True
StockManagementList.FullRowSelect = True
Dim lowStockCount = HelperMethods.ReviewLowStock()
ReviewLowStockButton.Text = "Review Low Stock (" & lowStockCount & ")"
LoaderForm.ParseStatus("Refreshing open orders ...")
RefreshAllOpenOrdersList()
loaderForm.ParseStatus("Refreshing needs attentions?") ' etc
RefreshNeedsAttentionList()
RefreshStockManagementList()
loaderForm.Finish()
End Sub
But Visual Studio has a neat thing called SplashScreen in its project templates for VB.NET. I'd use that one, if you aren't already…
Edit: I corrected the syntax errors in the code.

Programmatically add controls to form

I'm using the attached code to add another line\row of controls beneath an existing set (when a label is clicked). There could be quite a few rows added so I'm having to repeat the code many times using the counter (i) to keep track...
Is there a better method for doing this?
Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LblExpandSearch.Click
If i = 0 Then
'TextBox7
'
Dim TextBox7 As New TextBox
TextBox7.Size = New Size(302, 20)
TextBox7.Name = "TextBox7"
TextBox7.Location = New System.Drawing.Point(60, 135)
Me.ExpAdvancedSearch.Controls.Add(TextBox7)
'RadioButton5
'
Dim RadioButton5 As New RadioButton
RadioButton5.AutoSize = True
RadioButton5.Checked = True
RadioButton5.Location = New System.Drawing.Point(77, 112)
RadioButton5.Name = "RadioButton5"
RadioButton5.Size = New System.Drawing.Size(55, 17)
RadioButton5.TabIndex = 48
RadioButton5.TabStop = True
RadioButton5.Text = "NEAR"
RadioButton5.UseVisualStyleBackColor = True
ElseIf i = 1 Then
ExpAdvancedSearch.Size_ExpandedHeight = 260
'TextBox8
'
Dim TextBox8 As New TextBox
TextBox8.Size = New Size(302, 20)
TextBox8.Name = "TextBox8"
TextBox8.Location = New System.Drawing.Point(60, 185)
Me.ExpAdvancedSearch.Controls.Add(TextBox8)
'RadioButton9
'
Dim RadioButton9 As New RadioButton
RadioButton9.AutoSize = True
RadioButton9.Checked = True
RadioButton9.Location = New System.Drawing.Point(77, 162)
RadioButton9.Name = "RadioButton9"
RadioButton9.Size = New System.Drawing.Size(55, 17)
RadioButton9.TabIndex = 48
RadioButton9.TabStop = True
RadioButton9.Text = "NEAR"
RadioButton9.UseVisualStyleBackColor = True
End If
i = i + 1
End Sub
Hmmm.. UseVisualStyleBackColor says 'winforms' to me.
A few points...
Don't add controls all to one panel, use a usercontrol.
Then just add instances of that.
Don't process click events from a label
Use a linklabel or button. Anything else = being mean to users. Of course it makes sense to you, you thought of it! Now so with users, this is black and white.
Sample...
Very minimal of course. You'll want to:
Put the items in a scrollable panel instead of right on the form.
Add them to a generic list of uc probably, too.
Set form's min/max size - to allow reasonable sizing (allow any height > ~100)
Set uc's and controls .Anchor properties to allow reasonable resizing
uc.vb
Public Class uc
Inherits System.Windows.Forms.UserControl
Private components As System.ComponentModel.IContainer
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
Public Sub New()
MyBase.New()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
Me.SuspendLayout()
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(88, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
Me.LinkLabel1.Enabled = False
Me.LinkLabel1.Location = New System.Drawing.Point(112, 8)
Me.LinkLabel1.Name = "LinkLabel1"
Me.LinkLabel1.Size = New System.Drawing.Size(24, 16)
Me.LinkLabel1.TabIndex = 1
Me.LinkLabel1.TabStop = True
Me.LinkLabel1.Text = "add"
Me.Controls.Add(Me.LinkLabel1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "uc"
Me.Size = New System.Drawing.Size(148, 36)
Me.ResumeLayout(False)
End Sub
Private _addcallback As EventHandler = Nothing
Public Property AddCallback() As EventHandler
Get
Return _addcallback
End Get
Set(ByVal Value As EventHandler)
_addcallback = Value
LinkLabel1.Enabled = Not Value Is Nothing
End Set
End Property
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
If AddCallback Is Nothing Then Throw New ApplicationException("AddCallback not set on a uc") ' ALWAYS check for errors like this
_addcallback(Me, Nothing)
AddCallback = Nothing ' gray myself out, can't insert in thie implementation
End Sub
End Class
frm.vb
Public Class frm
Inherits System.Windows.Forms.Form
Private components As System.ComponentModel.IContainer
Public Sub New()
MyBase.New()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddClicked(Me, Nothing)
End Sub
Private Sub AddClicked(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myuc As New uc
myuc.AddCallback = AddressOf AddClicked
If Controls.Count > 0 Then
myuc.Top = Controls(Controls.Count - 1).Bottom
End If
Me.Controls.Add(myuc)
End Sub
End Class
I don't know if there's a "less code" approach to this but I do know that you can save your fingers using a With statement.
Dim RadioButton5 As New RadioButton
With RadioButton5
.AutoSize = True
.Checked = True
.Location = New System.Drawing.Point(77, 112)
.Name = "RadioButton5"
.Size = New System.Drawing.Size(55, 17)
.TabIndex = 48
.TabStop = True
.Text = "NEAR"
.UseVisualStyleBackColor = True
End With
If you need to add an indefinite number of items to a single page, then you need to store those items in an array list that we can later add to the page dynamically.
Imports System.Collections.Generic
Partial Class Default2
Inherits System.Web.UI.Page
''# the i integer is here for helping to set the ID of the radio button
''# as well as the tabindex
Private Shared _i As Integer
Public Shared Property i As Integer
Get
Return _i
End Get
Set(ByVal value As Integer)
_i = value
End Set
End Property
''# we need to create an array of our control list class
Public Shared _ctrlList As List(Of ControlList)
''# page load event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
''# if the page is not a postback, then we need to initialize the Control List
_ctrlList = New List(Of ControlList)
i = 0
End If
End Sub
''# button click event
Protected Sub button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button.Click
''# create a new RadioButton every time the button is clicked
Dim rb As RadioButton = New RadioButton
With rb
.ID = "radioButton" + i.ToString
.Checked = True
.TabIndex = 48 + i
.Text = "NEAR"
End With
''# create a new literal every time the button is clicked
Dim lt As Literal = New Literal
With lt
.ID = "literal" + i.ToString
.Text = " <strong>my fancy text</strong><br />"
End With
''# add the radio button and literal to our custom array
_ctrlList.Add(New ControlList(rb, lt))
''# loop through the array and add the controls to the page
For Each cl In _ctrlList
LabelPlaceHolder.Controls.Add(cl.RadioBtn)
LabelPlaceHolder.Controls.Add(cl.Litrl)
Next
''# increment the i counter so that we have unique radioButton ID's
i = i + 1
End Sub
''# this is our custom Control List
''# the idea behind this is for us to store
''# an array of Radio Buttons and literals to
''# spit out onto the page
''# NOTE: you can add as many controls as you like
''# to this list and even add static "Literals" to
''# help you with your formatting (IE: DIV tags or <BR> tags
Public Class ControlList
Private _RadioBtn As RadioButton
Public Property RadioBtn As RadioButton
Get
Return _RadioBtn
End Get
Set(ByVal value As RadioButton)
_RadioBtn = value
End Set
End Property
Private _Litrl As Literal
Public Property Litrl As Literal
Get
Return _Litrl
End Get
Set(ByVal value As Literal)
_Litrl = value
End Set
End Property
Public Sub New(ByVal radioBtn As RadioButton, ByVal litrl As Literal)
_RadioBtn = radioBtn
_Litrl = litrl
End Sub
End Class
End Class
Try this and see how it works. All you need in your ASPX is
<form id="form1" runat="server">
<asp:PlaceHolder runat="server" id="LabelPlaceHolder" /><br />
<asp:Button ID="button" runat="server" Text="click me" />
</form>
Basically what this does is add an additional control set to the page every time the button is clicked. You can have an indefinite number of controls on the page without adding any additional code.

Cant create 2nd textbox

I'm having problems with this code and I can't figure out why. It works fine the first time through but crashes with a "Parameter is not Valid" error the 2nd time through on this line:
Dim tbx As TextBox = New Windows.Forms.TextBox
The full code is as follows:
Dim tbx As TextBox = New Windows.Forms.TextBox
tbx.Name = tbxName
tbx.Size = New System.Drawing.Size(55, 12)
tbx.BorderStyle = BorderStyle.None
tbx.TextAlign = HorizontalAlignment.Center
Using f As Font = tbx.Font
tbx.Font = New Font(f.FontFamily, 8, FontStyle.Bold)
End Using
tbx.Location = New System.Drawing.Point(xCords, 44)
Select Case tbx.Name
Case "tbxBulk01" : tbx.Text = Bulk01Label
Case "tbxBulk02" : tbx.Text = Bulk02Label
End Select
Me.Controls.Add(tbx)
Here's the stack trace:
at System.Drawing.Font.GetHeight(Graphics graphics)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at System.Windows.Forms.Control.get_FontHeight()
at System.Windows.Forms.TextBoxBase.get_PreferredHeight()
at System.Windows.Forms.TextBoxBase.get_DefaultSize()
at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
at System.Windows.Forms.TextBoxBase..ctor()
at System.Windows.Forms.TextBox..ctor()
Any help is appreciated.
I know this is an old question but here is my answer.
I suspected the
USING .... END USING section as well.
I have just read that in the feedback too, oh well, never mind.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xCoords As Integer = 80
Dim myTextBox As TextBox = New TextBox
For index As Integer = 1 To 2
myTextBox = New TextBox
myTextBox.Name = "MyTextBox" & index.ToString
myTextBox.Size = New System.Drawing.Size(55, 12)
myTextBox.BorderStyle = BorderStyle.None
myTextBox.TextAlign = HorizontalAlignment.Center
myTextBox.Font = New System.Drawing.Font(myTextBox.Font.FontFamily, 8, FontStyle.Bold)
myTextBox.Location = New System.Drawing.Point(index * xCoords, 44)
Select Case index
Case 1 : myTextBox.Text = "Bulk01Label"
Case 2 : myTextBox.Text = "Bulk02Label"
End Select
Me.Controls.Add(myTextBox)
Next
End Sub
End Class