|
|||||||
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
PowerPoster
Join Date: Jan 04
Posts: 2,531
![]() |
I'm dynamically creating controls and inserting them into a Panel. My problem is that I'm creating a Checkbox control (setting various properties) and then a Label control (setting various properties). I wish for the text for each of the controls to be Black and Red respectively. They are to be right beside each other with a blank space separating them. The code I have provided does this if the for loop contains 1 iteration. If their are more than 1 iteration, the Red Asterisk doesn't show up. I've tried adding spaces between each occurrence of the checkbox and it still won't show up. Anyway, here is my code:
Code:
If resp Is Nothing Then
Dim asterisk As New Label
asterisk.Text = "*"
For Each row As DataRow In ds2.Tables(0).Rows
Dim chk As New CheckBox
chk.AutoSize = True
chk.Top = 7
chk.BackColor = pnl1.BackColor
chk.ForeColor = Color.Black
chk.TextAlign = ContentAlignment.MiddleLeft
chk.Text = row("labelName")
chk.Left = tmpWidth
Me.pnl2.Controls.Add(chk)
If row("required") = "Y" Then
asterisk.Top = chk.Top
asterisk.Left = chk.Width
asterisk.ForeColor = Color.Red
Me.pnl2.Controls.Add(asterisk)
tmpWidth = tmpWidth + chk.Width + 25
Else
tmpWidth = tmpWidth + chk.Width
End If
AddHandler chk.Click, AddressOf CheckBox1_Click
Next
End If
__________________
Blake |
|
|
|
|
|
#2 |
|
Invisible
Join Date: May 02
Posts: 13,263
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Changing colors of an Object and inserting into another Object???
sooo.... you need a label with an asterisk in it and a check box... for each row? right?
Seems to me then, your label would need to be created inside your loop... not outside... -tg
__________________
How to Use Parameters * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.* * Got Eels in your Hovercraft? * * Your guide to The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft * *Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming. "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN MVP '06-'10
|
|
|
|
|
|
#3 |
|
PowerPoster
Join Date: Jan 04
Posts: 2,531
![]() |
Re: Changing colors of an Object and inserting into another Object???
If the For Loop has 1 iteration....the code does what it is supposed to do. The problem is when there are more than 1 iterations of the Loop. I think it has to do with the spacing between each CheckBox. The Asterisk is placed on the right side of the checkbox....so, it would seem that the subsequent checkboxes are overlaying the position of the Asterisk....but I can't be sure of that because I have tried incrementing the space between each checkbox and the asterisk still won't appear.
__________________
Blake |
|
|
|
|
|
#4 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Changing colors of an Object and inserting into another Object???
I'd suggest that you use a TableLayoutPanel. You simply set the number of columns to two and just alternately add the controls. The TLP will automatically grow to the appropriate number of rows.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
|
#5 |
|
Frenzied Member
Join Date: Jun 05
Location: South UK
Posts: 1,653
![]() ![]() ![]() ![]() |
Re: Changing colors of an Object and inserting into another Object???
As techgnome suggests the label should be defined in the loop and also
Code:
asterisk.Left = chk.Width Code:
asterisk.Left = chk.Right Code:
Dim tmpwidth As Integer = 0
Dim asterisk As Label
For i As Integer = 0 To 5
asterisk = New Label
asterisk.AutoSize = True
asterisk.Text = "*"
Dim chk As New CheckBox
chk.AutoSize = True
chk.Top = 7
chk.BackColor = Me.BackColor
chk.ForeColor = Color.Black
chk.TextAlign = ContentAlignment.MiddleLeft
chk.Text = i.ToString
chk.Left = tmpwidth
Me.Controls.Add(chk)
If "Y" = "Y" Then
asterisk.Top = chk.Top
asterisk.Left = chk.Right
asterisk.ForeColor = Color.Red
Me.Controls.Add(asterisk)
tmpwidth = tmpwidth + chk.Width + 25
Else
tmpwidth = tmpwidth + chk.Width
End If
Next
__________________
_________________________________________________________________________________ B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved. Last edited by Bulldog; Jun 19th, 2007 at 08:36 PM. |
|
|
|
|
|
#6 |
|
PowerPoster
Join Date: Jan 04
Posts: 2,531
![]() |
Re: Changing colors of an Object and inserting into another Object???
Thanks guys...that worked!
__________________
Blake |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|